More granular multi-site folder setup

I have a 4-URL project I’m setting up. Content for each site is in its own folder, but I’m using the same accounts, blueprints, and templates across all four sites (so they are using the same “site” folder).

I was wondering if it’s possible to get even more granular with the folder routing. For instance, I’d like to separate the templates for each of these sites (something like site/templates/website-a/), but still keep common blueprints and accounts.

Even better, if there was a way to have “default” fallback templates across the whole multisite, but have site-level template files override the default. This, I’m sure, will take some coding, but I don’t know enough about the Kirby internals to know where to start.

A stopgap solution I came up with is to drop this at the top of my templates:

// if site/templates/{site}/{template-file} exists, use instead
if (file_exists(__DIR__ . DS . kirby()->urls()->site . DS . "home.php")) {
  include __DIR__ . DS . kirby()->urls()->site . DS . "home.php";
  exit;
}

It’s not super elegant, and it means the code has to be on each of my default templates. Hoping somebody’s got a better idea.

Right now you can’t change the template, snippet etc. directories separately by overriding the paths from your site.php file. I opened a PR a few days ago that lets you do that. But there’s no default.php fallback functionality in there though.

2 Likes