Skip to content

Kirby 6.0.0

Routes

Routes are registered with the routes extension.

The extension accepts an array of routes, where each route is defined as an array of key/value pairs. You have to define at least a pattern and an action.

/site/plugins/your-plugin/index.php
Kirby::plugin(
  name: 'your/plugin',
  extends: [
    'routes' => [
      [
        'pattern' => 'my/awesome/url',
        'action'  => function () {
          // do something here when the URL matches the pattern above
        }
      ]
    ]
  ]
);

Routes can also be registered as callbacks. Within the callback they have full access to the current Kirby instance.

Kirby::plugin(
  name: 'demo/plugin',
  extends: [
    'routes' => function ($kirby) {
      return [
        [
          'pattern' => '...',
          'action' => function () {

          }
        ]
      ];
    }
  ]
);

For more information on routing see the routing docs