Subsites
Last updated: Jun 10, 2024

Introduction

Subsites are used for creating different versions of a website, such as making it multilingual. They can also be used for A/B testing purposes.

Any part of the website that affects the output in a specific way can be 'subsited.' This includes forms, navigations, pages, categories, data collections, and more.

Sections and your existing view files can be used for all subsites.

Creating subsites

Subsites are easily created in the CMS. Simply go to 'Tools' -> 'Subsites' and click 'Add Subsite.'

The only thing you need to do is specify a name, a handle and a URL for your new subsite. The name is for your own reference, but the handle can be used later on to determine which subsite should be shown.

When you have created your first subsite, you can optionally rename the default sitename, go to 'Tools' -> 'Settings' and change the 'Main subsite name' under the 'CMS' tab. This field is only present, when you have 1 or more subsites.

Filling subsites

To have different content on different subsites, you need to add a variant for the new subsite. This example demonstrates how to do this for a global, but the process is the same for any entity you want to make available in the subsite.

Go to the globals overview. You will see that a subsite column has been added to the overview. Click 'Clone' under the actions pane of the global you want to make available in the new subsite. Choose a unique name for your reference and select the subsite where this global should be placed.
IMPORTANT: If you are reusing your existing view files, keep the handle of the new global identical to the original.

Determining the subsite

By default Webigniter automatically detects the right subsite based on the URL. So if you visit the website using the URL specified in the subsite, that specific subsite will be loaded. If no match can be found, the default site is shown.

If you want to manualy determine the subsite, you can add a parameter to the Webigniter initialization.

$webigniter = new WebigniterClient('YOUR_KEY', subsite: 'german'); //This loads the subsite with handle 'german'.

You can remove this extra parameter or make null if you want to show the default site.

The handle can be found in the subsites overview in the CMS, when logged in as an admin.

So if you want to show different languages of your website based in the domain name, you can use this example.

if($_SERVER['HTTP_HOST'] == 'mydomain.de')
{
    $subsite = 'german';
}
else{
    $subsite = null;
}

$webigniter = new WebigniterClient('YOUR_KEY', subsite: $subsite);

Now if the domain name is mydomain.de, all content will be collected from the subsite with handle german. If not, the default site is loaded.

1