I just tried out the new route filter function but I did not get it to work like expected.
- The first route matches anything.
- If it finds a page prefixed with
items/
likeitems/about
it will returntrue
and run the action. - The action will fire if it matches correctly.
All the steps above work, so the first route work… as long as I don’t add a second one.
$kirby = kirby();
$kirby->set('route', [
'pattern' => '(:any)',
'filter' => function($route) {
if( ! page('items/' . $route->arguments[0]) )
return false;
},
'action' => function($uid) {
return site()->visit('items/' . $uid);
}
]);
/*$kirby->set('route', [
'pattern' => '(:any)',
'action' => function() {
echo 'Overwritten';
}
]);*/
If someone like @texnixe or @lukasbestle are doing a test, run the uncommented code first and make sure it works.
Second route
When uncommending the second route, it will run instead of the first one, writing Overwritten
on the screen. Because the first route successfully matched, it should go to that action and visit the page and never even go down to the second route?
Just to make it super clear. I expected the success of the first route to prevent the second route to take over.
Maybe I understand the concept of filter wrong, maybe it’s a bug, I don’t know.
Another case
Two similar routes that does not work together like this. It always takes the last route no matter what I do.
$kirby->set('route', [
'pattern' => '(:any)',
'filter' => function($route) {
if( ! page('items/' . $route->arguments[0]) )
return false;
},
'action' => function($uid) {
return site()->visit('items/' . $uid);
}
]);
$kirby->set('route', [
'pattern' => '(:any)',
'filter' => function($route) {
if( ! page('_pages/' . $route->arguments[0]) )
return false;
},
'action' => function($uid) {
return site()->visit('_pages/' . $uid);
}
]);