I am very new to umbraco and i am staill struggling to learn the basics. I am working on a site that was developed my someone else couple of months ago. I have come across the navigation problem. The structure of the site is like this:
And the code for the navigation in the xslt files is like this:
I want the header to always display the contents or the nodes in simple website, however when i click on a page which come from *news folder, the header changes to the nodes names from that particular folder. How do i make sure that the header navigation stays the same no matter which page i click ?
This happens because the navigation looks for the ancestor at level 1 to be the root of the menu (which normally is the case - many Umbraco sites have a single root node containing the site nodes) - but when you're in the news section it'll obviously find the "### News" node instead - the trick here is to make sure to find the correct top node, which you can do by going all the way to the <root> element first, and then selecting the "Simple website" node relative to that instead. It also makes everything much easier to read (and modify):
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:umbraco.library="urn:umbraco.library"
exclude-result-prefixes="umbraco.library"
>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:param name="currentPage" />
<!-- Go all the way up to the <root> containg everything --> <xsl:variable name="absoluteRoot" select="$currentPage/ancestor::root" />
<!-- You can do this one by @id too, if you want e.g.: $absoluteRoot/*[@id = 1234] -->
<xsl:variable name="simpleSiteRoot" select="$absoluteRoot/*[@nodeName = 'Simple website']" />
<xsl:template match="/">
<ul id="topNavigation">
<li class="home">
<xsl:if test="$currentPage/@id = $simpleSiteRoot/@id">
<xsl:attribute name="class">home current</xsl:attribute>
</xsl:if>
<a href="/">Home</a>
</li>
<xsl:for-each select="$simpleSiteRoot/*[@isDoc][not(umbracoNaviHide = 1)]">
<li>
<a class="navigation" href="{umbraco.library:NiceUrl(@id)}">
<span><xsl:value-of select="@nodeName" /></span>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
wow ! thanks a lot Chriztian. The code worked perfetcly fine. I knew that it had to do something with the root level etc but i was not sure how to change it. I really appreciate your quick response...
How to make the header navigation stay the same ?
Good Morning everyone,
I am very new to umbraco and i am staill struggling to learn the basics. I am working on a site that was developed my someone else couple of months ago. I have come across the navigation problem. The structure of the site is like this:
And the code for the navigation in the xslt files is like this:
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
<li>
<a class="navigation" href="{umbraco.library:NiceUrl(@id)}">
<span><xsl:value-of select="@nodeName"/></span>
</a>
</li>
My problem:
I want the header to always display the contents or the nodes in simple website, however when i click on a page which come from *news folder, the header changes to the nodes names from that particular folder. How do i make sure that the header navigation stays the same no matter which page i click ?
Would i have to restructure my enitre contents ?
Please advise !
Thanks
the entire code:
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:param name="currentPage"/>
<!-- Input the documenttype you want here -->
<xsl:variable name="level" select="1"/>
<xsl:template match="/">
<ul id="topNavigation">
<li class="home">
<xsl:if test="$currentPage/@id = $currentPage/ancestor-or-self::* [@level=$level]/@id">
<xsl:attribute name="class">home current</xsl:attribute>
</xsl:if>
<a href="/">Home</a>
</li>
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
<li>
<a class="navigation" href="{umbraco.library:NiceUrl(@id)}">
<span><xsl:value-of select="@nodeName"/></span>
</a>
</li>
</xsl:for-each>
</ul>
Hi ashwini,
This happens because the navigation looks for the ancestor at level 1 to be the root of the menu (which normally is the case - many Umbraco sites have a single root node containing the site nodes) - but when you're in the news section it'll obviously find the "### News" node instead - the trick here is to make sure to find the correct top node, which you can do by going all the way to the <root> element first, and then selecting the "Simple website" node relative to that instead. It also makes everything much easier to read (and modify):
/Chriztian
wow ! thanks a lot Chriztian. The code worked perfetcly fine. I knew that it had to do something with the root level etc but i was not sure how to change it. I really appreciate your quick response...
is working on a reply...