Thread

Problem with Pagination and Template Routes

June 20, 2017 12:29pm

Subscribe [3]
  • #1 / Jun 20, 2017 12:29pm

    glawrie

    13 posts

    I have an established site that was working just fine, but following a point-upgrade of EE (3.5.6 to 3.5.9) template routes that include a pagination term have all stopped working. I am mystified as to what is going on - maybe someone can suggest either a fix or a way to find out what is going on…

    I have several template routes of the form /resources/category/{page:pagination} segments=no.

    Currently any two-segment URL that would match this type of route (e.g. /resources/public-sector) goes to a 404. Identical URLs with a pagination term (e.g. /resources/public-sector/P5) work as they should.

    If I send a URL that has a random third segment to the route (e.g. /resources/public-sector/stuff) the route goes to a 404 (correctly).

    However, if I send a URL that has a third segment that has the form of a pagination term, but a lower case letter (e.g. /resources/public-sctor/p7) the route returns the opening page (what I should have got when there is no third segment).

    I realise that with cleverness I could use a single route for all the various categories, but for various reasons all the various categories have their own route (so one for /resources/public-sector, a similar but separate one for /resources/presentations etc.) - and this behaviour is replicated across all of them.

    Does anyone know what is going on here? Anyone seen it before?

    Thanks alot for any help on this.

  • #2 / Jun 23, 2017 8:00pm

    glawrie

    13 posts

    This turned out to be a bug, which appears to have been around since 3.4.0.

    Temporary fix ℅ Ellis Labs is to replace the static segment 2 element with regex to achieve same end: no idea why it works, but it does. So, for example, to get the example route from question to work, you need to modify it as follows:

    /resources/{seg_2:regex[(public\-sector)]}/{page:pagination}

    Posting answer here in case it is useful for someone else.

  • #3 / Nov 03, 2017 7:46am

    louisk

    39 posts

    I have been cracking my brain on this for hours. Finally found out that it had to do with the :pagination part. So I found this post.

    Tried the solution and it worked!!

    I upgraded an EE2 site to EE3 and all kept on working for a long time until I had to add another template route, and had to re-save the template route page. Thats when the segments with :pagination stopt working.

    This bug has to be fixed since I presume lots of sites use the :pagination part.

    Here are the routes:

    EE2
    Old route: /blog/{page:pagination}
    Old route_parse: ^blog\/?(?P<edu1z29t9o6go84scooo4og48gg8k0sk>(((?=\b((P|R|N)[0-9]+)\b)([^\/]*))))?\/?$
    EE3
    New route: /blog/{page:pagination}
    New route_parse (ERROR): ^(blog)\/((?P<edu1z29t9o6go84scooo4og48gg8k0sk>(((?=\b((P|R|N)[0-9]+)\b)([^\/]*)))))?\/?$
    EE3 FIX
    New route (FIX): /{seg_1:regex[(blog)]}/{page:pagination}
    New route_parse (FIX): ^((?P<eljyvok1nuio4c8oc0k8oogcscw8gcgg>(((?=\b(blog)\b)([^\/]*)))))\/?((?P<edu1z29t9o6go84scooo4og48gg8k0sk>(((?=\b((P|R|N)[0-9]+)\b)([^\/]*)))))?\/?$

    Hope it helps

  • #4 / Nov 03, 2017 9:16am

    louisk

    39 posts

    I have just discovered that this problem is more complex and applies if you have other variables than :pagination.

    I have this template route:

    /product/{product_detail_page:alpha_dash}/enquire/{response:success}

    And have to change it to the following to make it work:

    /product/{product_detail_page:alpha_dash}/{seg_3:regex[(enquire)]}/{response:alpha_dash}

    The name you use as segment variable doesn’t matter in this case.

    In my template I do use the “response” segment.

  • #5 / Nov 03, 2017 9:49am

    glawrie

    13 posts

    Hi Louis

    Great - thanks for posting what you found.

    It is indeed a more complex problem than just pagination - and one that apparently EllisLabs can’t fix (to do so would break some other stuff or somesuch) - but hopefully it will be done in V4…

    In the interim I never managed to fully resolve the issues with use of the routes with variables - to get site to work under EE3 I ended up going back to a myriad of manually coded one-shot routes to template folder each containing a template redirect back to the common template shared across (in my case) categories. Horrible solution, hard to maintain, and still didn’t work with pagination (which I ended up removing from site).

    I really like some bits of EE, but bluntly this kind of thing does the CMS no favours at all.

  • #6 / Nov 06, 2017 8:31pm

    travisb

    168 posts

    Not an answer for your direct issue, but I would suggest exploring Resource Router as an alternative to the native template routes. Might be too much of a rework at this point, but Resource Router for reference.

ExpressionEngine News

#eecms, #events, #releases