[FR] Site group-based templates #8564
-
DescriptionIf there is only translation between localized site, we probably dont need to add new templates
But with multiple sites + localization,
Can we make use of siteGroup concept, and workout something like this:
|
Beta Was this translation helpful? Give feedback.
Replies: 13 comments 15 replies
-
Seems reasonable! |
Beta Was this translation helpful? Give feedback.
-
Just to note it here. This sounds similar to the need we had for Site Groups with a plugin supporting multi-lingual sitemaps. Nice to see another use case appear for those Site Groups. |
Beta Was this translation helpful? Give feedback.
-
+1 Also give Site Groups some sort of handle. That is also set on the |
Beta Was this translation helpful? Give feedback.
-
+1 I would love to see this functionality implemented. |
Beta Was this translation helpful? Give feedback.
-
+1 |
Beta Was this translation helpful? Give feedback.
-
Looking forward to this, wondering if there's a clean work-around in the current setup. |
Beta Was this translation helpful? Give feedback.
-
There's a PR for this |
Beta Was this translation helpful? Give feedback.
-
Has anything changed since 2018? I'd like to have templates per site group as well. Can't find any info on the docs on how to accomplish this, so I suppose it hasn't been developed? |
Beta Was this translation helpful? Give feedback.
-
Just here to add my +1 We have a multi-site installation that will have two sites added annually from now on. 2020 in German and 2020 in English are already in place, now 2021 in both languages will be added. Templates will change across these two new sites, but they will be localized only between each other. If we have to duplicate the templates into de2021 and en2021 template folders, we'd be at 4 duplicates come 2022. Due to it being legacy code, some tricks (like including/extending by site group) won’t work without me having to touch all the default (2020) code. I’m looking for workarounds, but having a regular way to overwrite templates on a site group basis would solve it perfectly. |
Beta Was this translation helpful? Give feedback.
-
I'm looking at Craft 4 docs to see if anything has changed on this but as far as I can tell it has not? |
Beta Was this translation helpful? Give feedback.
-
So a small update, seems like the Craft 4.0 label was removed 10 days ago, had a look at the 5.0 roadmap but it isn't mentioned on it anywhere. Curious to see if this is something that's still on the radar. Was hoping to use this feature in some upcoming project. Some insights on timing and/or wether or not this is ever going to be implemented would be nice. |
Beta Was this translation helpful? Give feedback.
-
For anyone wanting this feature: you could as well just create a symlink for your other sites. That's what I usually do in that case
siteGroupTemplates contains all the real templates, SiteA and SiteB are just empty folders with a link to siteGroupTemplates |
Beta Was this translation helpful? Give feedback.
-
We have decided not to implement this feature. In addition to @Anubarak’s symlink-based solution, another way you can approach this is with a custom use Craft;
use craft\events\RegisterTemplateRootsEvent;
use craft\helpers\StringHelper;
use craft\web\View;
use yii\base\Event;
Event::on(
View::class,
View::EVENT_REGISTER_SITE_TEMPLATE_ROOTS,
function(RegisterTemplateRootsEvent $event) {
$site = Craft::$app->sites->getCurrentSite();
$group = StringHelper::toCamelCase($site->getGroup()->name);
$event->roots['_siteGroup'] = Craft::getAlias("@templates/_siteGroups/$group");
}
); From there, create a
Your templates can then reference site group-specific templates via |
Beta Was this translation helpful? Give feedback.
We have decided not to implement this feature.
In addition to @Anubarak’s symlink-based solution, another way you can approach this is with a custom
_siteGroup
template root, defined by a bootstrapped module or private plugin: