0

I could swear this was working last week.

I've got Resource Router set up like so:

':url_title' => function($router) {
$router->setTemplate('addon/index');
$router->setGlobal('template', 'addon');
},
':url_title/faqs' => function($router) {
    $router->setTemplate('addon/faqs');
$router->setGlobal('template', 'addon');
},
':url_title/changelog' => function($router) {
    $router->setTemplate('addon/changelog');
$router->setGlobal('template', 'addon');
},
':url_title/documentation' => function($router) {
    $router->setTemplate('addon/documentation');
$router->setGlobal('template', 'addon');
}

and it works.

However, I've just started to notice that if I try /blog the template that gets served is addon/index.

'blog' is not a URL title that exists in the database and this is happening for other template groups as well.

Like I say, this has been working and only just seeing it has stopped coming back to the project this morning.

If I were to alter my routes like:

'blog' => 'blog',
'blog/:url_title' => 'blog/post',
'voucher' => 'voucher',
'members' => 'member',
':url_title' => function($router) {
$router->setTemplate('addon/index');
$router->setGlobal('template', 'addon');
},

it works, but I'd rather rely on native EE routing for these template groups.

1 Answer 1

2

:url_title will match any string that could be a url title as it is converted to ([^/]+) [1]

To stop this rule matching template groups, you can check that the match is for a real entry in the expected channel like this:

':url_title' => function($router, $wildcard) {
    // valid entry in the 'home' channel (id=3)?
    if ($wildcard->isValidUrlTitle(array('channel_id' => 3))) {
        $router->setTemplate('addon');
        $router->setGlobal('template', 'addon');
    }
},

[1] Note: ^ is added to the start and $ to the end of the rule automatically by Resource Router, so the actual url pattern matched is ^([^/]+)$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.