I have a structure setup with parents and children. Can a route be setup in the CP to route a generic url to a specific parent or child of the structure. For example I have a blog landing page that is a child of the structure. Can a route be setup, so when a user enters at /blog it takes them to that landing page?
2 Answers
What I would do is create a structure siteUrls which is responsible for page urls. Top-level entries have url of {slug}, nested entries have url of {parent.uri}/{slug}. The top-level entry with slug blog will be the entry with url /blog. Then you can have an entry type of blogLandingPage and use that entry type for this entry.
The other piece of the puzzle is getting the right template for the blogLandingPage. The trick for this is to use a feature of the twig include tag:
New in version 1.2: The possibility to pass an array of templates has been added in Twig 1.2.
You can also provide a list of templates that are checked for existence before inclusion. The first template that exists will be included:
So your template for siteUrls will look like:
{% include ['_siteUrls/'~entry.type, '_siteUrls/default'] %}
And the template for entries (like this one) with type blogLandingPage is _siteUrls/blogLandingPage. Using a list for the {% include %} means some entry types can share templates, and thing fail more gracefully if you have an entry type without a matching template.
- 12,047
- 22
- 55
Not 100% sure I follow what you're trying to do, but here's what I'd suggest (based on my interpretation)...
- Create an actual template, either
blog.htmlorblog/index.html. - In that template, write a couple simple lines of Twig code which will (A) determine which page they are supposed to be routed to, then (B) redirect to that page.
- 23,974
- 5
- 53
- 110
config/routes.phpfile, but that also denies the client of their "ease of marketing" desire. – Lindsey D Sep 04 '14 at 05:15