Join us for EEConf 2023, October 4-5 in Orlando. Speakers. Networking. Community powered. Awesome.
Join us for EEConf 2023, October 4-5 in Orlando.
Register Now!Hi,
We’re using template routes for news article routing:
Channel: News. Template news/detail. Route: news/detail - /news/{art}/ - all segments.
Works perfectly: /news/todays-news-article
Would like to change the route to news/today/{art}/ for example. Fails.
Is there a way to have multiple segments in the route?
Thanks!
HI,
The way I have handled that sort of thing before is to forget about routes for something like that & create a template in your news.group for “today” and then just call the appropriate entries. Although, thinking on it, that may not be too practical if the intent is to allow the user to sort by a time period.
I have done that with product entries before. “site.com/products/item/{url_title}”
Unclear from your question quite what you are doing - but it looks like you have set up your EE installation with a template group called “news”.
If so, then EE will automatically try to open any url_title that is appended to /news
using the default template in the template group “news”.
So the behaviour you are describing as “working” is simply the default behaviour of EE. Accordingly it is quite possible that the template route you have entered is not doing anything at all; the failure of your modified template route / url combination to work also suggests that this is the case.
Template routes have been known to be buggy and unreliable in EE at least since EE4, and although some work has been done by the EE team to fix some issues, they remain a feature that you should avoid using if you can.
In your case there does not appear to be any need for a template route to achieve the outcome you describe. EE’s default behaviour (i.e. without routes defined) would be to route the url /news/today/something
to the default template in in the ‘news’ template group anyway. To display the page (presumably defined by the entry with url_title something
) you simply need to modify your {exp:channel:entries}
tag (or whatever equivalent you are using) to refer to the {last_segment} rather than {url_title}
- doing so would ensure that the template retrieves data both for entries with the url form /news/something
and /news/today/something
.
If you want the processing of today
entries to be different then you can use some conditionals within your template looking at the value for {segment_2}
.
HTH
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.