The Kirby extension registry

Hello Kirby-Friends,

I just had a look at the Kirby extension registry, which I wanted to use in my Podcast-Plugin and in an AMP-Plugin I am currently working on. But I don’t get quite behind it.

I just set up the base of my plugin and played around a bit. What I am trying to do is, registering a route, implementing a controller and then load a specific template.

So I just copied the route I currently have in my config.php and tried to register it:


$kirby->set('route', 'amp', array(
	'pattern' => '(:any)/amp',
	'action'  => function() {

function amp() {
    // void

(I shortened it here)

So what I was awaiting: When I now remove my original route from the config.php (which worked) and have this registration in my plugin, I should still be able to open a page like:

But now I do get a 404 error.

I am pretty sure, I am missing something here, but I don’t see it.
Can you give me a hint?

Looks like the syntax should be like this:

$kirby->set('route', [
		'pattern' => 'staticbuilder',
		'action'  => 'Kirby\Plugin\StaticBuilder\siteAction',
		'method'  => 'GET|POST'

(stolen from the staticbuilder plugin …)

Thank you, I’ll try this and report here, if it works :slight_smile:
I thought there always has to be a third parameter, like here:

The registry syntax for routes is a bit different from other ones, @texnixe maybe open a bug so that the documentation adds a route example?

@mauricehh I think your issue was the second parameter, which for routes must be the route’s config array apparently. This should work better:

$kirby->set('route', array(
	'pattern' => '(:any)/amp',
	'action'  => function() {

And your action should return a Page object or a response, but I think you were already doing that if it was working before.


Thank you for your help, removing the second parameter helped, it’s now working :slight_smile:

The set version of register routes does not allow multiple routes in the same set, right?

Is is a benefit of register a new set every time a new route is added? Would it be better to use the old syntax for register multiple routes?

Yes I’m full of questions about it. :slight_smile:

You can reply here instead: