Recently upgraded an older Expression Engine site from 1.x.x to 2.7.3, and looking to upgrade to 2.9.0 and optimize some of the slower code. One of the issues I'm working on is getting rid of a lot of embed tags, which were used in the old site to embed navigation, using embed variables to set classes to display active links in the embedded navigation template.
I'm looking for some general guidance on Expression Engine best practices to do something like that - with the goal of finding a solution that can do it with the least queries and load the fastest, even when dealing with a lot of conditionals in the navigation.
This is what I want to happen: when on site/about, the navigation menu will be rendered like this:
<ul>
<li><a class="selected" href="{site_url}about">About Us</a></li>
<li><a href="{site_url}about/community">Community</a></li>
<li><a href="{site_url}about/people">Directory</a>
</ul>
The idea is that the "selected" class changes depending on the template that's being loaded to let users know where they are in the site..
So far, I've considered the following possibilities:
Use preparse in Low Variables:
Template: site/about
{exp:low_variables:single var="lv_subnav_about" preparse:selected="about"}
Low Variable: lv_subnav_about
<ul> <li><a {if selected == 'about'} class="selected"{/if} href="{site_url}about">About Us</a></li> <li><a {if selected == 'community'} class="selected"{/if} href="{site_url}about/community">Community</a></li> <li><a {if selected == 'people'} class="selected"{/if} href="{site_url}about/people">People: Directory</a> </ul>
- Revising the scheme to use segments instead of passing variables to accomplish the same goal. This would still probably require the same number of conditional statements in the embed/low variable, but would using segments help at all, performance-wise?
- Using the new (in EE 2.8.x) layout variables to do the same thing, i.e. {layout="site/normal" selected="about"}. This would have another advantage in that I could create layouts that take care of other embeds I'm trying to get rid of - header/footer/sidebar/etc.
Please let me know if you have any ideas on what the best way to accomplish this goal might be, even when dealing with much more complex navigation (passing multiple variables to indicate category and page, etc) - thanks!