Hello,
Beginner Umbraco user here, but am a Sitecore-certified developer, and notice an amazing number of similarities between the platforms. Must be a coincidence.
Anyway, I'm building a top nav menu where I just want to render the whole tree of Content items under 'Home' as nested unordered lists. Umbraco xsl seems to work a little differently that what I'm used to, so I want to ask if there's a better way to do it than this:
Code:
<xsl:param name="parent">Home</xsl:param>
<xsl:template match="/">
<xsl:call-template name="menu">
<xsl:with-param name="parent" select="$parent"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="menu">
<xsl:param name="parent"/>
<ul>
<!-- add css class for topmost ul -->
<xsl:if test="$parent='Home'">
<xsl:attribute name="class">top_menu</xsl:attribute>
</xsl:if>
<!-- iterate over all elements of the current level -->
<xsl:for-each select="$currentPage/ancestor::root//node[@nodeName=$parent]/node [string(data [@alias='umbracoNaviHide']) != '1']">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
<xsl:attribute name="class">nav_selected</xsl:attribute>
</xsl:if>
<xsl:value-of select="@nodeName"/>
</a>
<!-- test for children, recurse if found -->
<xsl:if test="count(descendant::node [string(data [@alias='umbracoNaviHide']) != '1']) > 0">
<xsl:call-template name="menu"><xsl:with-param name="parent" select="@nodeName"/></xsl:call-template>
</xsl:if>
</li>
</xsl:for-each>
</ul>
</xsl:template>
Thanks,
- Andrew