2

Usage Scenario
One organization with branches in several cities. Most of the events in one city are only advertised to that one city, but some of the larger events in any given city will be advertised for the other cities. While the different branches are similar, some have many offerings (categories), and some just a few.

What we used to do
In Craft 2, we had one single URL shared by all the cities, one large set of categories which mapped to the drop-down menus, and entries as events that fall into the categories.

What we want to do
Individual URLs for the different cities, focusing on the offerings in that city, but a few from other cities.

Dilemma / Question
Since we don't need multiple versions of the events entries, it seems that we need very little of the multi-site functionality. Just needing to call different templates with different navigation and css, depending on the request URL.
In
Settings > Sections > Events --> Site Settings
is it necessary to

  • switch on all the light switches, and
  • check Propagate entries across all enabled sites?

It seems this might triple the size of the database.

  • What does this have to do with multi site? Do you want to have different languages or different sites? It seems one entry should just have different urls but this doesn't require multi site. You can just use Yii2 routing in order to load different asset bundles. You can include a custom behavior for those entries to fetch the url for each different available route and use your custom function instead of the getUrl() to link to those entries – Robin Schambach May 11 '18 at 7:52
  • What he said. Multi-site sounds overkill. It sounds like you just need different subdomains and with a bit of template variation tested for using that. In Craft 2 you could do it using {% set domain = craft.request.getServerName() %} {% if domain starts with 'london' %}{% include '_incs/_londonNav' %} They'll be similar for Craft 3. – Clive Portman May 11 '18 at 8:24
1

Thank you very much, Robin and Clive.

Note: I think there are better answers than what I have written here, such as this but they didn't appear to me after writing this.

In case it might benefit anyone, it's clear there are many ways to do this. My setup does not use Craft's "multi-site" capabilities, but has three urls pointing to the same index.php. It functions more or less as follows:

Folder Structure

craft/config/sitedata.php
craft/templates/_genericPageTemplate.html
               /mifc/_navigation.html
                    /local.css
               /migr/_navigation.html
                    /local.css
               /miwy/_navigation.html
                    /local.css
public_html/index.php

Main Page Template

Now starts with:

{% set domain = craft.app.request.ServerName %}  
{% set siteUrl = '//' ~ domain ~ '/' %}  
{% set env = getenv('ENVIRONMENT') %}  
{% set sitesData = craft.app.config.getConfigFromFile('sitedata')[env] %}  
{% set siteData = sitesData[domain] %}  
{% set categoriesToDisplay = siteData.nativeCategoryIds|merge(siteData.sharedCategoryIds) %}  

and later brings in the css and navigation depending on site:

<link rel='stylesheet' id='localCss'  href='/{{siteData.handle}}/local.css' type='text/css' media='all' />
...
{% include siteData.handle~'/_navigation.html' %}

Config File

In {% set sitesData = craft.app.config.getConfigFromFile('sitedata')[env] %}
the page template references craft/config/sitedata.php which contains stuff specific to each site, both for production and development:

<?php

/**
 * Return an array indexed by locale code
 */

return [
   'production' => [
        'site1.org' => [
            'live'                  => true,
            'handle'                => 'mifc',
            'nameInMenus'           => 'Fort Collins',
            'siteTitleSuffix'       => 'Fort Collins Meditation & Modern Buddhism',
            'url'                   => 'site1.org',
            'titleMainBig'          => 'Meditation & Buddhism',
            'titleSmallerSecondLine'=> 'Heruka Buddhist Center in Fort Collins and the Surrounding Areas',
            'topNativeCategoryIds'  => [194,195,220],
            'nativeCategoryIds'     => [194,198,10,11,14,196,7,1775,2476,5,4,9,6,8,267,2073,195,63,66,67,20,70,71,220,12,221,222,1688,223],
            'topSharedCategoryIds'  => [13,60],
            'sharedCategoryIds'     => [13,60],
        ],
        'site2.org' => [
            'live'                  => true,
            'handle'                => 'migr',
            'nameInMenus'           => 'Greeley',
            'url'                   => 'site2.org',
            'siteTitleSuffix'       => 'Greeley Meditation & Modern Buddhism',
            'titleMainBig'          => 'Meditation & Buddhism in Greeley',
            'titleSmallerSecondLine'=> 'Heruka Buddhist Center in Greeley',
            'topNativeCategoryIds'  => [197],
            'nativeCategoryIds'     => [197,3112,58,61,2940,59,62,60],
            'topSharedCategoryIds'  => [198,67,13],
            'sharedCategoryIds'     => [198,10,11,14,67,13],
            'eventsCategoryIds'     => [60,198,10,11,14,67,13],
        ],
        'site3.org' => [
            'live'                  => true,
            'handle'                => 'miwy',
            'nameInMenus'           => 'Wyoming',
            'url'                   => 'site3.org',
            'siteTitleSuffix'       => 'Wyoming Meditation & Modern Buddhism',
            'titleMainBig'          => 'Meditation & Buddhism in Wyoming',
            'titleSmallerSecondLine'=> 'Heruka Buddhist Center in Wyoming',
            'topNativeCategoryIds'  => [3151],
            'nativeCategoryIds'     => [3151,2969,65,64,68,69,72],
            'topSharedCategoryIds'  => [198,60,13],
            'sharedCategoryIds'     => [198,10,11,14,60,13],
            'eventsCategoryIds'     => [60,198,10,11,14,67,13],
        ],
    ],
    'dev' => [
        'f.dev' => [
            'live'                  => true,
            'handle'                => 'mifc',
            'nameInMenus'           => 'Fort Collins',
            'siteTitleSuffix'       => 'Fort Collins Meditation & Modern Buddhism',
            'url'                   => 'f.dev',
            'titleMainBig'          => 'Meditation & Buddhism',
            'titleSmallerSecondLine'=> 'Heruka Buddhist Center in Fort Collins and the Surrounding Areas',
            'topNativeCategoryIds'  => [194,195,220],
            'nativeCategoryIds'     => [194,198,10,11,14,196,7,1775,2476,5,4,9,6,8,267,2073,195,63,66,67,20,70,71,220,12,221,222,1688,223],
            'topSharedCategoryIds'  => [13,60],
            'sharedCategoryIds'     => [13,60],
        ],
        'g.dev' => [
            'live'                  => true,
            'handle'                => 'migr',
            'nameInMenus'           => 'Greeley',
            'url'                   => 'g.dev',
            'siteTitleSuffix'       => 'Greeley Meditation & Modern Buddhism',
            'titleMainBig'          => 'Meditation & Buddhism in Greeley',
            'titleSmallerSecondLine'=> 'Heruka Buddhist Center in Greeley',
            'topNativeCategoryIds'  => [197],
            'nativeCategoryIds'     => [197,3112,58,61,2940,59,62,60],
            'topSharedCategoryIds'  => [198,67,13],
            'sharedCategoryIds'     => [198,10,11,14,67,13],
            'eventsCategoryIds'     => [60,198,10,11,14,67,13],
        ],
        'w.dev' => [
            'live'                  => true,
            'handle'                => 'miwy',
            'nameInMenus'           => 'Wyoming',
            'url'                   => 'w.dev',
            'siteTitleSuffix'       => 'Wyoming Meditation & Modern Buddhism',
            'titleMainBig'          => 'Meditation & Buddhism in Wyoming',
            'titleSmallerSecondLine'=> 'Heruka Buddhist Center in Wyoming',
            'topNativeCategoryIds'  => [3151],
            'nativeCategoryIds'     => [3151,2969,65,64,68,69,72],
            'topSharedCategoryIds'  => [198,60,13],
            'sharedCategoryIds'     => [198,10,11,14,60,13],
            'eventsCategoryIds'     => [60,198,10,11,14,67,13],
        ],
    ]
];

Feel free to point out any mistakes, etc, in this way of doing things.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.