Forum
Navigation needing to target ancestor_page and subitems
Hi,
I need to have classes added to a navigation item if it's the ancestor_page (class of 'active') and if it's got subitems (class of 'submenu-button')
The problem is the navigation list item could have both of these. I have the following which works but throws a validation error if both are true, as the 'active' class is applied twice.
<perch:before>
<ul id="sidr" class="menu">
</perch:before>
<li<perch:if exists="current_page"> class="active"</perch:if><perch:if exists="ancestor_page"> class="submenu-button active"</perch:if><perch:if exists="subitems"> class="submenu-button"</perch:if>><a href="<perch:pages id="pagePath" />"><perch:pages id="pageNavText" /></a><perch:pages id="subitems" encode="false" /></li>
<perch:after>
</ul>
</perch:after>
Is there a way to check if it has subitems and it's the ancestor before applying the classes?
You mean like this?
Yes then I would need to do
So both don't get picked up? It seems to work :)
I think personally I'd be more inclined to do something like
Thanks Drew.