0

I am working on a sidebar navigation here. The navigation works correctly but I am trying to highlight the active entry.

In the past I have been able to use a segment_3 conditional to tag the active entry with a class="active", however, something is missing in my approach this time.

I have tested for segment_3 and I have tested for {url_title} but when I put them together like this, I don't get any results:

<ul>
 {exp:channel:entries channel="services" sort="asc" dynamic="no" }
    <li {if segment_3 == "{url_title}"} class="active" {/if} ><a href="/services/detail/{url_title}">{title}</a></li>
 {/exp:channel:entries}
</ul>

I would appreciate some guidance on how to resolve this.

  • Which version of EE are you using? – stuartmcd69 Apr 1 '16 at 4:08
2

See if wrapping segment_3 in matching quotes and curly brackets helps. I think I remember stumbling upon that issue in my early EE days and it dealing with parse order; keeping it matching helped in my case and was something I got in the habit of doing. I believe with EE 2.9+ they recommend not to put quotes around variables as they've updated the template parser to behave more as you'd expect it to. Anyway, I'm rambling as if this is the solution and I'm almost confident it is, but let us know if it still fails.

<ul>
 {exp:channel:entries channel="services" sort="asc" dynamic="no" }
    <li {if "{segment_3}" == "{url_title}"} class="active" {/if} ><a href="/services/detail/{url_title}">{title}</a></li>
 {/exp:channel:entries}
</ul>
  • Also consider using {last_segment} instead of specifying a specific segment. – Peter Lewis Apr 1 '16 at 7:24
  • I could have sworn I had tried that option. Nevertheless it works. Thanks. – fmz Apr 1 '16 at 18:35

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.