Different blueprints same template

Hello, I have two pages. They each have a unique blueprint. I’d like them to use the same template. Is this possible? Using the default template is not an option?

I have pretty much the same logic in these two pages. Maybe I should include the code of one template in the other?


1 Like

If they have a unique blueprint, you obviously can’t use the same template. You could use the default template, or use two templates but include the same snippet.

Understood. Thanks for confirming.

I know this is a bit of a thread revival, but I would find the ability to share templates amongst blueprints incredibly helpful.

My specific use case: in the website I’m currently working on, I have just one “Directory” template that is used in a lot of different contexts. Here’s just a small sample:

  • A “Jobs” page with a list of available jobs.
  • An “Events” page with a list of upcoming events.
  • A “Resources” page with a list of external links and internal pages.
  • A “News” page, similar to a simple blog.

It makes sense for these pages to use the same PHP template, as they all share the same appearance and logic (they show their “children” in a list).

However, using the same template means that all of those directory pages also must use the same blueprint. Hence, I can’t specify that the “Jobs” page should only accept subpages with the “Job” template. Instead, I have to permit every single subpage template that could be used in any context. The end result is that when adding a subpage, my client is faced with a long list of irrelevant template choices to choose from, which is not ideal.

I could just add a bunch of templates for every single directory type and handle the logic in a snippet, but that just doesn’t feel very DRY to me and would almost double my current template count.

Then I’d use the default template and make sure all other pages have a specific blueprint. Another option would be routes that load a template, but you would then have to pass all data to the template in your route, well, maybe not all because you can use a default controller, but some.

It is also possible to register your template for different models using the registry.

// Assuming you have a template called list.php
$kirby->set('template', [
], $kirby->roots()->templates() . DS . 'list.php');

On top they would all share the same controller.


@lukaskleinschmidt, you are my hero! That worked like a dream.