1

So I've got a multisite going on.

For most of the sites, most of the time, they'll be using the same templates. But I want a good way to handle siteX needing one template to be different from the other sites.

For example, when going to siteX.com/news, I'd like for the template served to be siteX/news.html if it exists, otherwise default/news.html.

I know I could change the template path in the DB, but I'd rather keep it in the code for development/deployment simplicity.

I think I could could create custom routes, but I'd rather not create a route for every section.

At the moment I'm doing this by creating a root/news.html file, which just says {% include [currentSite.handle ~ '/news', 'default/news'] %}

but it'd be nice to not have to do this for every template I create. It also seems inefficient to do this on a template level (though I don't actually know this to be true).

So the questions are:

  1. (How) can I overwrite Craft's template resolver to do what I want?
  2. Is this the best way to go about this?

Thanks!

1 Answer 1

3

You can create localized template files by placing them in a subfolder of templates/ named after the site handle.

See https://docs.craftcms.com/v3/dev/#template-localization for a full explanation.

1
  • Can't believe I missed this default behaviour. Thanks!
    – mijewe
    Commented Dec 14, 2018 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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