Bug #21633 Accepted

Template routes with static segments and require all set to ‘no’ error.

Version: 3.1.2 Reporter: Robin Sowell

Given this route: /add/{url_title:alpha_dash} with require all ‘no’ I would expect http://mysite.com/index.php/add to match it (assuming the first route in order).  It doesn’t.  It matches if all segments are present: http://mysite.com/index.php/add/something - but not if that second segment is missing.

This can be worked around with a more complex regex:

/{company:alpha_dash}/{seg2:regex[(gallery)]}/{page:pagination}
  • I had the exact same problem. I (temporarily) fixed this by removing lines 124 - 127:

    if (is_object($segment) && empty($segment->parts))
    {
        $add_question_mark = FALSE;
    }

    In file /system/ee/legacy/libraries/template_router/Route.php. You have to update the template routes trough the cp in order to generate the new regex.

    Not really sure why these lines are in there, for now it seems to do the trick without creating any additional problems.

    Expertees
    31st March, 2016 at 10:26am
  • I am having this same problem in the latest release of 3.4.2. Can anyone update me if this is being looked into?

    Chris Davies
    12th September, 2016 at 5:10am
  • As a workaround to avoid hacking, you could create an add template group and let its index template handle the requests when there is no second segment. You would be able to stay DRY by embedding the actual template, with no other tags on add/index. For instance if this route goes to the template group foo and the template bar, add/index would just contain:

    {embed='foo/bar'}
    Derek Jones
    07th April, 2017 at 11:59am
  • Just for the record, this bug is still in play with EE 3.5.9.

    Only solution that works is to create {embed='foo/bar'} duplicates of the template to cover all routing options and then set up static routes to each. An appalling hack - given that Template Routes is supposed to be providing this (and pretty much only) this service, for it to be broken over a minimum of four point upgrades (3.1 -> 3.5) is very poor.

    Is anything being done to fix this?

    glawrie
    17th July, 2017 at 9:23am
  • Sorry for the inconvenience, @glawrie, please see Kevin’s comments here, which explain why a fix has not been made in a minor release.

    Derek Jones
    17th July, 2017 at 10:20am
  • The existing documentation for Template Routes is pretty poor - but it might be a kindness to include somewhere within that rats-nest a very clear label saying that some of the features described therein don’t actually work, and won’t ever work in this version of EE. Would save others time I think.

    glawrie
    17th July, 2017 at 11:15am

You must be signed in to comment on a bug report.

ExpressionEngine News

#eecms, #events, #releases