Mixing Other Templates into Static Navigation
So - you’ve used one of the approaches here on Train-ee.com to build dynamic navigation from posts in an ExpressionEngine weblog—but now you want to mix in a link to a different page type - say a contact form. And, you want this link to be sorted in the middle of the navigation items coming from weblog posts. How to do that?
For the purposes of demonstration, let’s assume I have an existing section of simple static content with navigation to each page showing in the sidebar. I now want to add a “Contact Us” page in this section, and the page needs to have a fill in the blank form. I want the navigation to this new contact page to show up in the same list as the other pages in this section, but would rather use a different template to create the page.
Here’s what I would do:
- Create a new post in the weblog holding my static content. In this case I’d title it “Contact Us” which would get me a URL title of “contact_us”. Make sure to note the URL title.
- Enter some dummy content - it won’t appear on the website so it doesn’t matter what you put in. I usually put a note of “Don’t delete this entry as it’s used to create navigation”.
- Save the new entry.
- Just for kicks, go to your site and refresh things to ensure the new entry is showing up in the navigation.
- Now return to the template group that contains the templates used to create your static content. Create a new template.
- This is the important part - make sure to name the new template such that it matches the URL title as your placeholder entry - so in my case the new template is called “contact_us”.
- Add the necessary code to the new template and save it.
- Go back to your site, navigate away from the placeholder page and click the “Contact Us” in the navigation again. EE should load your new template rather than the placeholder entry from the static content weblog.
What we’re taking advantage of here is how EE processes URLs and the order it looks for things. It looks for templates before content entries, so the new template will get loaded rather than the static content placeholder entry.
Overall this is just a neat little trick that lets us use weblog entries from one weblog to build navigation to a number of different templates - templates that may or may not draw content from the same weblog as the navigation comes from.
Note that you could keep all this functionality in one EE template, and use segments and conditionals to analyze the URL and either show static content or the contact form. How you approach the build is up to you - for me it seems each site has more or less a fixed amount of complexity, and I can either build fewer but more complex templates or more templates that are individually less complex. In other words - I can squish that complexity into either a tall and narrow shape, or a short and fat shape - but the shape has the same surface area…if that makes sense. Often I’ll make a decision based on what’s going to be the quickest to figure out a year from now when I’ve forgotten how the site went together and have to look at the code to remember…which for me tends to be the more-but-simpler-templates approach.
Category Navigation





by
Date: Sunday, September 28th, 2008
Comment: #1
Hello Mike.
“What we’re taking advantage of here is how EE processes URLs and the order it looks for things.“
Is this behavior working with EE 1.6.4?
It is not working for me. The entry page content is displayed even if both the entry and template have the same URL title. And…yes…both share the same template group.