I am trying to set a conditional on a navigation element using segmentation, and this works fine except when I hit the pagination stuff.

The pagination is in increments of 50 so I tried the following but it only works if the page is P50.

<li><a {if segment_2 == "" OR segment_2 == "article" AND segment_2 >="P50"}class="active"{/if} href="{site_url}news/">Clean Energy News</a></li>
<li><a {if segment_2 == "releases"}class="active"{/if} href="{site_url}news/releases">News Releases</a></li>
<li><a {if segment_2 == "multimedia"}class="active"{/if}{if segment_2 == "photos"}class="active"{/if} href="{site_url}news/multimedia">Multimedia</a></li>
<li><a {if segment_2 == "archive"}class="active"{/if}href="{site_url}news/archive">News Archive</a></li>

Is there a conditional I can put on segment_2 that will work? Note that I have other nav elements that I don't want it to interfere with. Thanks!

2 Answers 2


Take a look at the MD Detect Page Type or Switchee addons.


For navigation, whether I am using an embed method or the template partials with Stash approach, I find it easier to pass a parameter specifying which section I want active rather than trying to detect it manually.

In my experience there is always an edge case requiring a more manual / granular approach that will defeat any automatic setup down the road.


In main template

{embed="embeds/.header" active_nav="articles"}

In embedded template

    <li><a{if embed:active_nav == "articles"} class="active"{/if} href="{site_url}articles/">Articles</a></li>
    <li><a{if embed:active_nav == "news"} class="active"{/if} href="{site_url}news/">News</a></li>

template partials

In partial template

{exp:stash:set_value name="active_nav" value="articles"}

In layout (.main) template

    <li><a{if "{exp:stash:get name='active_nav'}" == "articles"} class="active"{/if} href="{site_url}articles/">Articles</a></li>
    <li><a{if "{exp:stash:get name='active_nav'}" == "news"} class="active"{/if} href="{site_url}news/">News</a></li>

Variant with body class only

In partial template

{exp:stash:set_value name="body_class" value="body_articles"}

In layout template

<body{if {exp:stash:not_empty name="body_class"}} class="{exp:stash:get name='body_class'}"{/if}>

    <li class="articles"><a href="{site_url}articles/">Articles</a></li>
    <li class="news"><a href="{site_url}news/">News</a></li>

in your CSS

.body_articles .articles > a
    do something

From the two add-ons mentioned by Anna, I would go down the switchee route

{exp:switchee variable="{segment_2}" parse="inward"}

    {case value="#^P(\\d+)$#|''"}
        code if pagination page

    {case default="Yes"}
        code if not a pagination page


The advantage of switchee beeing that, if you have channel entries loops or anything heavy process-wise, it only get executed should the tested condition apply. Better for performance.

  • No problem. Hope it will help fmz too. Using such a method for navigation instead of a more automated solution really saved my bacon on some occasions Jan 14, 2013 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.