How to use the Routes in Kirby 2.2+

Hi there, I would like to know what is the correct use for multiples filters for a route in Kirby 2.2+

For URLs like…

  1. Must I use the following way?

       'pattern' => array(
       'action'  => 'Routes::checkout'
  2. Or?

       'pattern' => 'checkout/(\w{6})|(\w{2})/checkout/(\w{6})',
       'action'  => 'Routes::checkout'

If there is any other way to use it, please, let me know.

Also, I would like to know if there is a way to group the routes, It would be very convenient for multi language sites.

You can make the language code optional:

  'pattern' => '(?:(\w{2})/)?checkout/(\w{6})',
  'action'  => 'Routes::checkout'

Your solution is Stunning!! :smile:, I’m going to fix my routes just now

Anyway, I would like to know how to use the “Pipe syntax” for the routes for Kirby 2.2… If you throw me a guide, It would be great!!

Which pipe syntax are you referring to?

I’m referring to… Please check the line into change log at:

  • Option to add multiple filters to a single route by using the pipe syntax


This line in the changelog is referring to filters, not patterns. The difference is that patterns determine whether a route matches and which parts of the URL should be extracted while filters are functions that are called before the route’s action is called. They allow to make sure a route action is only called if the user is authenticated for example. Filters are being used for the Panel and are a very specific and advanced feature.

The syntax for patterns is a regular expression and not specific to Kirby. :smile:

1 Like

If you want to use multiple patters for the same route, you can separate them by commas.

    'pattern' => array('blog/(:any)', 'events/(:any)'),
    'action'  => function($uid) {

Or use regular expressions, as you already do.

As @lukasbestle explained, the pipe syntax refers to filters, to separate multiple filter, you can use a pipe |. But in your current use case, I don’t think that’s what you need.

1 Like

Thanks for you explanation, I was a little bit confused with that :grin: