Developer forum

Forum » CMS - Standard features » InPath and Active in nav xml

InPath and Active in nav xml

Thomas Schroll
Reply

Hi

I'm trying to put an "active" on a menu element and its parents by using

<xsl:if test="@Active='True' or @InPath='True'">active </xsl:if>

in my xslt. It does not work because every InPath attribute in my xml are false and the only Active attribute that is true is the home element. I'm using

<ul id="main-menu" class="dwnavigation collapse navbar-collapse navbar-static-top" data-settings="endlevel:2;expandmode:all;template:NavMainMegaDropdown.xslt">

in my template.

Does anybody know why the attributes are not set to true?

Regards Thomas

 


Replies

 
Mikkel Ricky
Reply

From what you show above it should work, i.e. @InPath should be True for all nodes in the current path and @Active should be True for the current page.

However, if you have Ecom groups in your navigation the attributes are only set correctly when you have a Product Catalog on the page where the Ecom group are attached. Maybe this is the issue?

Best regards,
Mikkel

 
Thomas Schroll
Reply

Hi Mikkel

There isn't Ecom groups attached, however it seems like it's only on item pages it isn't working. On regular pages it works fine.

Can't InPath and Active attributes be used on item pages?

Regards Thomas

 
Mikkel Ricky
Reply

The InPath and Active attributes work for both regular pages and item based pages – at least it works for me running 8.4.1.

What version of Dynamicweb are you runinng? Do you have a solution we can take a look at?

 
Thomas Schroll
Reply

Hi Mikkel

The version is 8.5.0.1 at pz.net.dynamicweb-cms.com

Regards Thomas

 
Mikkel Ricky
Reply
This post has been marked as an answer

As far as I can tell the attributes InPath and Active works just as expected on that site (using SaveXml=true in the url and inspecting the generated xml next to the navigation xslt).

The issue is in your navigation xslt:

<xsl:if test="@Active='True' or @InPath='True'">
  <xsl:attribute name="class">current-menu-item active</xsl:attribute>    
</xsl:if>
<xsl:if test="count(child::Page) > 0">
  <xsl:attribute name="class">dropdown yamm-fw</xsl:attribute>
</xsl:if>

 

Any page having children will only get the classes "dropdown yamm-fw", but never "current-menu-item active". 

Try using something like this instead

<xsl:variable name="class-names">
  <xsl:if test="@Active='True' or @InPath='True'"> current-menu-item active </xsl:if>
  <xsl:if test="Page"> dropdown yamm-fw </xsl:if>
</xsl:variable>
<xsl:if test="normalize-space($class-names)">
  <xsl:attribute name="class">
    <xsl:value-of select="normalize-space($class-names)"/>
  </xsl:attribute>
</xsl:if>

 

Best regards,
Mikkel

Votes for this answer: 1
 
Thomas Schroll
Reply

Thanks Mikkel

I was so careful to check the xml, but obviously not careful enough. Of course I didn't see the second class overwriting the first, so thanks for that.

Regards Thomas

 

You must be logged in to post in the forum