0

What's the syntax for excluding phrases from segments in template routes?

For example, let's say I have a template group called "fruit."

I have a template A with the template route: "/fruit/{fruit:alpha-dash}" and that route matches:

  • /fruit/apples
  • /fruit/oranges
  • /fruit/tomatoes

But I'd like to exclude just tomatoes from using template A so that it can match template B which is the next sequential template.

What would the regex look like to exclude tomatoes?

0

There is a top-down order for how template routes are processed. So what you need to do is create your tomato route rule, and make sure it is above your regular alpha_dash rule. I couldn't find a simple solution for ignoring specific segments in a regex rule using the carat and didn't bother testing further; EE would yell at me for using some regex modifiers and such. The other way around was easier. Here's what worked for me in your example.

This is an example of a couple of rules in your My site -> CP Home -> Design -> Template Manager -> Template Route Manager that works for your exmample:

Group     Template          Route                            Segment Req
-------------------------------------------------------------------------
fruit     special_fruit     /fruit/{fruit:regex[(tomato)]}   Yes
fruit     regular_fruit     /fruit/{fruit:alpha_dash}        Yes

This will match /fruit/tomato to your special_fruit template. When that doesn't match (say /fruit/apples), it tries the next rule and will match and render your regular_fruit template.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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