I have managed to replicate the menu, except I can not figure out how to add arrow graphics to the list items which have children. Please could you help.
Thanks
James
p.s I found a topic which poses the same question but the code is structured differently and I had trouble working it in to my code above.
I think you just need to count the child elements of the node you're at using the same if sentence you're calling the template with if further levels exists.
Try this out
<xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevel]"> <li> <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevel]) > 0"> <xsl:attribute name="class"><xsl:text>yourclassname</xsl:text></xsl:attribute> </xsl:if>
Top navigation template - How to add a class to list item if the node has children?
Hello, I am trying to build a menu like this:
and this is the code I am starting with Umbraco 4.5.2:
<?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" exclude-result-prefixes="msxml
umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<!-- update this variable on how deep your navigation should be -->
<xsl:variable name="maxLevel" select="4"/>
<xsl:template match="/">
<ul class="dropdown dropdown-horizontal">
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@level=1 and @isDoc]"/>
</xsl:call-template>
</ul>
</xsl:template>
<xsl:template name="drawNodes">
<xsl:param name="parent"/>
<xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
<xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevel]">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
<xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevel]) > 0">
<ul>
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="."/>
</xsl:call-template>
</ul>
</xsl:if>
</li>
</xsl:for-each>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
I have managed to replicate the menu, except I can not figure out how to add arrow graphics to the list items which have children. Please could you help.
Thanks
James
p.s I found a topic which poses the same question but the code is structured differently and I had trouble working it in to my code above.
http://our.umbraco.org/forum/templating/templates-and-document-types/5769-Submenu,-has-children-then-add-class-
Hi James
I think you just need to count the child elements of the node you're at using the same if sentence you're calling the template with if further levels exists.
Try this out
<xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevel]">
<li>
<xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevel]) > 0">
<xsl:attribute name="class"><xsl:text>yourclassname</xsl:text></xsl:attribute>
</xsl:if>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
<xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevel]) > 0">
<ul>
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="."/>
</xsl:call-template>
</ul>
</xsl:if>
</li>
</xsl:for-each>
If there is childnodes the class attribute will be set with a value of "yourclassname" :-)
Hope this helps
/Jan
Jan,
Perfect!
Thankyou :)
James
is working on a reply...