Plugin Template and Subfolder mess

Hi, i am brand new to kirby. I try to create my first plugin, an render a plugin-template to a page…

simple root

$kirby->set('template', 'my-page', __DIR__ . DS.'templates'.DS.'test.php');

$kirby->set('route', array(
    'method' => 'GET',
    'pattern' => 'test',
    'action' => function () {

    $my_data = [ 'foo' => 'thats foo',
                'bar' => 'thats bar'];
    return array('my-page', $my_data); 

I figured out that i have to place a dummy file in content folder to get it work:


So… this works perfectly. My test template in rendered within the rest of the page.


Now i tried to go a step further. I have a few Root-Pages (that also form the Main Menue). Under one of them are few Subpages, and one of these Subpages should be rendered by my plugin:

Following the above Schema i created a Dummy Page in the content Folder:


and modified my Plugin

$kirby->set('template', 'mitglied/laufzettel', __DIR__ . DS.'templates'.DS.'test.php');

$kirby->set('route', array(
    'method' => 'GET',
    'pattern' => 'mitglied/laufzettel',
    'action' => function () {

    $my_data = [ 'foo' => 'thats foo',
                'bar' => 'thats bar'];
    return array('mitglied/laufzettel', $my_data); 

 But that doesnt work. My Plugin-Template is ignored. Any ideas how to get this  scenario to work?

Hi @Carsten, welcome to the Kirby forum.

You register syntax is not correct, have a look here.

It should be

$kirby->set('template', 'test', __DIR__ . DS.'templates'.DS.'test.php');

So after template, there should be the name of the template, not a page name/id/path.

What are you trying to do?

On a side note: What is your reason for using Kirby 2 instead of Kirby 3? Kirby 2 will still have security updates till at least the end of this year, but is no longer actively developed.

Thank you, i look after that. I want to develop a plugin for a client (not really client, more friends)… their Webpage (4gb diskspace) bases on kirby2. I recommended an update to Kirby3 before i start my dev, but the websites deveplopers wanted to stay on Kirby 2 for a while. What i plan to do:

Develop my plugin on Kirby 2 and parallel for Kirby 3, and write some emails to underpin my recommendation for a migration. If nothing helps i do the job. Can not be that difficult, hu?

If the second parameter has to be the Templates Name, like so:

$kirby->set('template', 'test', __DIR__ . DS.'templates'.DS.'test.php');

My return value from the roothandler has also to be ‘test’

return array('test', $my_data);

and my Root Pattern is:

'pattern' => 'mitglied/laufzettel',

and the dummy page is…


So,this works like a charm.

But it doesnt reflect the Page Structure and the Menue.

The global Page Template under /sites/templates/ bzw. /sites/snippets/ renders a Menue like that:

<?php foreach($site->find('mitglied')->children()->visible() as $p): ?>
     <a <?php e($p->isOpen(), ' class="active"') ?> href="<?php echo $p->url() ?>"><?php echo $p->title()->html() ?></a>
<?php endforeach ?>

I Think, this code reflects the Filesystem Structure in…


My plugin should have a menu entry there, from which the plugin page is rendered when someone clicks on the link. The link should be highlighted, as indicated in this code snippet above:


How to achieve that with kirby?

The thing is, I don’t understand what you are trying to do here.

You register a template in a plugin, fine. This template will then be used for pages with a certain content file name.

Then you have a route. Your route now returns the dummy page with some additional data when the pattern mitglied/laufzettel is called.

But your routes are not pages only links that return something, so your menu will not show these routes unless you create the links manually.

Wouldn’t it make more sense to actually create these pages in the file system? Maybe not if you then had to create it for every mitglied…

(You can have virtual pages from any source in Kirby 3…)

Shurly it may be possible to add the entry manually in the global Template, but i have to append it at the left or right end of the Menu.

My Idea was to place a dummy page under


so that Kirby can render the menue, and make use of Kirbys Number mechanism to place the Menue Entry at a specific place. … and that leads to the question how to deposit a simple Link in the Menu Entry.

Puh, i now have an idea what my problem is… its about a really simple and common Task in Wordpress or in any handcraftet Websites. No idea to manage that with Kirby:

Calling a Custom-Link from a Kirby-Managed Menu. 


thank you for your patience lg Carsten

Where do you want to add the link, you can add it anywhere with an if statement.

$children = $site->find('mitglied')->children()->visible();
foreach($children as $p): ?>
<?php if ($children->indexOf($p) === 2): ?>
<!-- custom link here -->
<?php endif ?>
     <a <?php e($p->isOpen(), ' class="active"') ?> href="<?php echo $p->url() ?>"><?php echo $p->title()->html() ?></a>
<?php endforeach ?>

Or something like this…

I have a few hundret JSON Files wich contain Data for every Member. From this source i do some calculations, different Lists for Clients, and a Form to Edit the Json from the Admin.

Each Member File should be coupled with a user id of an registrated Sitemember.

:slight_smile: Thank you. The Board in front of my head is gone. This takes me a giant step further.