New umbraco content structure, sub navigation alternative
I have build the last couple Umbraco website with the following structure and have found it really good especially from a client perspective:
Content
Home
Page 1
Page 2
Page 3
Below is the XSLT I use to display the sub menu structure, just wondering if anyone can see a better way of doing this as it's still a manual process if at a later date the client want's to add an additional level to the menu.
Just a couple of pointers with this script, I pass in a parameter first so that the top level UL has a CSS class set, that way you can define your CSS for the menu based on that class.
Also the script is checking if a node is type is called redirectPage as this allows you to have menu items that re-direct externally.
I have hard coded the Level = 2 which is the start level for the menu structure, as this is very unlikely to ever change once a site has been built.
There is no maximum depth but you could of course add that within the IF statement that checks for child nodes and you could pass this parameter in as a macro variable so the user can set the depth.
New umbraco content structure, sub navigation alternative
I have build the last couple Umbraco website with the following structure and have found it really good especially from a client perspective:
Below is the XSLT I use to display the sub menu structure, just wondering if anyone can see a better way of doing this as it's still a manual process if at a later date the client want's to add an additional level to the menu.
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:param name="currentPage"/>
<!-- Defines how many levels the drop down should have. -->
<xsl:variable name="menuDepth" select="5" />
<xsl:template match="/">
<xsl:choose>
<xsl:when test="$currentPage/@level = 5">
<h4>
<xsl:value-of select="$currentPage/parent::node/parent::node/@nodeName" />
</h4>
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="umbraco.library:GetXmlNodeById($currentPage/parent::node/parent::node/@id)" />
</xsl:call-template>
</xsl:when>
<xsl:when test="$currentPage/@level = 4">
<h4>
<xsl:value-of select="$currentPage/parent::node/@nodeName" />
</h4>
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="umbraco.library:GetXmlNodeById($currentPage/parent::node/@id)" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<h4>
<xsl:value-of select="$currentPage/@nodeName" />
</h4>
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="umbraco.library:GetXmlNodeById($currentPage/@id)" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="drawNodes">
<xsl:param name="parent" />
<ul>
<xsl:for-each select="$parent/node">
<xsl:if test="string(./data [@alias = 'umbracoNaviHide']) != '1'">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:if test="$currentPage/@id = current()/@id">
<xsl:attribute name="class">activeItem</xsl:attribute>
</xsl:if>
<xsl:choose>
<xsl:when test="string-length(normalize-space(./data [@alias = 'naviTitle'])) = 0">
<xsl:value-of select="@nodeName" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="./data [@alias = 'naviTitle']" />
</xsl:otherwise>
</xsl:choose>
</a>
<xsl:if test="count(./node [string(./data [@alias = 'umbracoNaviHide']) != '1' and @level <= $menuDepth]) > 0">
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="." />
</xsl:call-template>
</xsl:if>
</li>
</xsl:if>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
Hi Nightwolf,
The XSLT I use ( and sometimes modify depending on the client requirement ) for a menu is as follows:
Just a couple of pointers with this script, I pass in a parameter first so that the top level UL has a CSS class set, that way you can define your CSS for the menu based on that class.
Also the script is checking if a node is type is called redirectPage as this allows you to have menu items that re-direct externally.
I have hard coded the Level = 2 which is the start level for the menu structure, as this is very unlikely to ever change once a site has been built.
There is no maximum depth but you could of course add that within the IF statement that checks for child nodes and you could pass this parameter in as a macro variable so the user can set the depth.
Cheers,
Chris
is working on a reply...