I have a submenu, the structure of if goes out to level 4, but when entering a subpage, i want those pages which has children to have a class called "hasChildren" - And when clicking the link that has children is gets 2 classes, "current and hasChildren" How do i do that?
<!-- Input the documenttype you want here --> <!-- Typically '1' for topnavigtaion and '2' for 2nd level --> <!-- Use div elements around this macro combined with css --> <!-- for styling the navigation --> <xsl:variable name="level" select="2"/> <xsl:variable name="minLevel" select="1"/> <xsl:template match="/">
<!-- The fun starts here --> <div class="leftmenu"> <xsl:if test="$currentPage/@level >= 3 or count($currentPage/child::node [string(data [@alias='umbracoNaviHide']) != '1' and @level = '3']) > 0"> <ul> <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']"> <li> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id"> <!-- we're under the item - you can do your own styling here --> <xsl:attribute name="class">selected</xsl:attribute> </xsl:if> <xsl:value-of select="@nodeName"/> </a> </li> </xsl:for-each> </ul> </xsl:if> </div> </xsl:template>
Submenu, has children then add class?
I have a submenu, the structure of if goes out to level 4, but when entering a subpage, i want those pages which has children to have a class called "hasChildren" - And when clicking the link that has children is gets 2 classes, "current and hasChildren" How do i do that?
My XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:param name="currentPage"/>
<!-- Input the documenttype you want here -->
<!-- Typically '1' for topnavigtaion and '2' for 2nd level -->
<!-- Use div elements around this macro combined with css -->
<!-- for styling the navigation -->
<xsl:variable name="level" select="2"/>
<xsl:variable name="minLevel" select="1"/>
<xsl:template match="/">
<!-- The fun starts here -->
<div class="leftmenu">
<xsl:if test="$currentPage/@level >= 3 or count($currentPage/child::node [string(data [@alias='umbracoNaviHide']) != '1' and @level = '3']) > 0">
<ul>
<xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
<!-- we're under the item - you can do your own styling here -->
<xsl:attribute name="class">selected</xsl:attribute>
</xsl:if>
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</div>
</xsl:template>
</xsl:stylesheet>
Hi Nicky,
This should get you off to a good start:
/Chriztian
Hey Chriztian...
Thx alot, just what i needed :)
is working on a reply...