Different blueprints same template – Reloaded (in Kirby 3)

Hi there,

I’m currently working on my first Kirby 3 project. :grin: My task:

I have a bunch of different blueprints. Each blueprint should share the same template (and controller).

In Kirby 2 the following code by @lukaskleinschmidt in this conversation placed in a plugin worked fine:

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

How can I achieve this in Kirby 3 plugin syntax?

This seems to work:

<?php 
Kirby::plugin('my/templates', [
    'templates' => [
        'jobs'   => kirby()->root('templates') . '/list.php'
        'events' => kirby()->root('templates') . '/list.php'
        // etc.
    ]
]);

The template can also live in the plugin folder, then you have to change the path.

1 Like

Thanks for your quick reply, @texnixe.

You’re a lifesaver! Keep on the good work. :heart:

I’ve just tried this but it doesn’t seem to respect the templates associated controller.

I have a template called note, and a controller called note.

I set up the list of blueprints, and add them to the list

<?php

Kirby::plugin('my/templates', [
    'templates' => [
        'note.gallery'   => kirby()->root('templates') . '/note.php'
        'note.article' => kirby()->root('templates') . '/note.php'
        // etc.
    ]
]);

This works and directs me to the correct template, but it breaks on variables defined in the note controller.

Is there a solution?

EDIT:

Don’t worry actually.

I can create models called note.gallery.php and define the template redirects there.

There’s now a new recipe with this solution, extended with controllers and models: