I'm evaluating umbraco and can't find out, how to get a multi-level menu.
I hope, somebody can explain, how the menu navigation code works.
As far as I understand the system, the xslt transforms the contents of the umbraco.config file, which is located in App_Data. In order to test my xslt code in Visual Studio I change two lines of the xslt code, so that currentPage is not a param, but a variable and the umbraco.library:NiceUrl is not used.
OK, I got it. The solution is umbraco.library.GetXmlAll(). This returns the cached xml, as it appears in the App_Data/umbraco.config. GetXmlAll() delivers directly the root node.
The complete and working code for a recursive menu is the following:
BTW, the HTML editor in your forum is simply not working. I tried to remove the code block at the end of my last post, but the editor window is completely confused, if I press the edit button. Some code disappears partly.
In this reply window I can't choose the code paragraph format....
- and then use $absoluteRoot instead of GetXmlAll().
The problem is that in the root template (match="/"), the / refers to a simple <macro> element that Umbraco uses to run the transformation. So we need to use $currentPage to connect to the Umbraco XML document, and we already have that available, so no need to call an extension function.
Try to understand the navigation xslt
Hi all,
I'm evaluating umbraco and can't find out, how to get a multi-level menu.
I hope, somebody can explain, how the menu navigation code works.
As far as I understand the system, the xslt transforms the contents of the umbraco.config file, which is located in App_Data. In order to test my xslt code in Visual Studio I change two lines of the xslt code, so that currentPage is not a param, but a variable and the umbraco.library:NiceUrl is not used.
My xslt looks like that:
My umbraco.config looks like that:
So the structure is:
Home
Das Buch
Subpage
Applying the given xslt to the umbraco.config gives me the wished result:
Now I change the two lines to let the xslt work in umbraco. I change
to
and
to
Starting the page with umbraco, gives me the following result:
It seems, that I didn't understand, how the xslt in umbraco works. Most umbraco examples I found by google use an xpath like
but this gives me no resuts.
delivers the Home page link only.
Could somebody explain, how the xslt works?
Best regards
mmaty
<?xml version="1.0" encoding="UTF-8"?>
<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" select="/root/umbTextpage[1]"/>
<!-- replacing the xsl:param with xsl:variable lets me test the code -->
<xsl:template match="/">
<xsl:call-template name="makeNode">
<xsl:with-param name="nodeLevel">1</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name ="makeNode" >
<xsl:param name="nodeLevel" />
<ul>
<xsl:for-each select="/root/descendant::* [@level=$nodeLevel]">
<li>
<xsl:if test="@id = $currentPage/@id">
<xsl:attribute name="class">current</xsl:attribute>
</xsl:if>
<!--a href="{umbraco.library:NiceUrl(@id)}" masked out for testing -->
<a href="@id">
<xsl:value-of select="@nodeName"/>
</a>
<xsl:variable name ="newLevel" select="$nodeLevel + 1" />
<xsl:if test="count(/root/descendant::* [@level=$newLevel]) > 0">
<xsl:call-template name="makeNode">
<xsl:with-param name="nodeLevel" select="$newLevel" />
</xsl:call-template>
</xsl:if>
</li>
</xsl:for-each>
</ul>
</xsl:template>
<!-- Never output these -->
<xsl:template match="*[umbracoNaviHide = 1]" />
</xsl:stylesheet>
OK, I got it. The solution is umbraco.library.GetXmlAll(). This returns the cached xml, as it appears in the App_Data/umbraco.config. GetXmlAll() delivers directly the root node.
The complete and working code for a recursive menu is the following:
BTW, the HTML editor in your forum is simply not working. I tried to remove the code block at the end of my last post, but the editor window is completely confused, if I press the edit button. Some code disappears partly.
In this reply window I can't choose the code paragraph format....
Regards
mmaty
Hi mmaty,
Actually, a better solution would be to set a variable after the currentPage param:
- and then use $absoluteRoot instead of GetXmlAll().
The problem is that in the root template (match="/"), the / refers to a simple <macro> element that Umbraco uses to run the transformation. So we need to use $currentPage to connect to the Umbraco XML document, and we already have that available, so no need to call an extension function.
/Chriztian
is working on a reply...