Problem getting choose construction to work correctly
Hi,
Ihave a some problems gettingmy chooseconstructionto work correctly in my main navigation.
So I hopesomeone can help me,Ihave become a littleblind onthis.
I havea fieldon mymasterdocument type,callednavigationtitle,andifthisisnot empty, it should be printedon the menu,but ifit is empty, then it shouldtakethe node name instead.
<xsl:template match="/">
<!-- The fun starts here --> <nav id="navigation" role="navigation" class="right"> <ul> <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']"> <li> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id"> <!-- we're under the item - you can do your own styling here --> <xsl:attribute name="class">selected</xsl:attribute> </xsl:if> <xsl:choose> <xsl:when test="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']/navigationTitle!=''"> <xsl:value-of select="navigationTitle"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']/@nodeName"/> </xsl:otherwise> </xsl:choose> </a> </li> </xsl:for-each> </ul> </nav> </xsl:template>
I have used the Navigation Prototype, as a start, and I´m use version 4.8.1 of the Umbraco CMS,
I hope, some one can point the little mistake out for me.
If I add the $currentPage/....stuff before the "navigationTitle" in the value-of, then I got nothing out in the menu.
<xsl:template match="/">
<!-- The fun starts here --> <nav id="navigation" role="navigationer" class="right"> <ul> <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']"> <li> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id"> <!-- we're under the item - you can do your own styling here --> <xsl:attribute name="class">selected</xsl:attribute> </xsl:if> <xsl:choose> <xsl:when test="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/*[@isDoc and string(umbracoNaviHide) != '1']/navigationTitle!=''"> <xsl:value-of select="$currentPage/navigationTitle"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$currentPage/@nodeName"/> </xsl:otherwise> </xsl:choose> </a> </li> </xsl:for-each> </ul> </nav> </xsl:template>
Problem getting choose construction to work correctly
Hi,
I have a some problems getting my choose construction to work correctly in my main navigation.
So I hope someone can help me, I have become a little blind on this.
I have a field on my master document type, called navigation title, and if this is not empty, it should be printed on the menu, but if it is empty, then it should take the node name instead.
I have used the Navigation Prototype, as a start, and I´m use version 4.8.1 of the Umbraco CMS,
I hope, some one can point the little mistake out for me.
/Dennis
Hi Dennis
You need to write the $currentPage/....stuff before the "navigationTitle" in the value-of :)
/Jan
Hi Jan,
If I add the $currentPage/....stuff before the "navigationTitle" in the value-of, then I got nothing out in the menu.
<xsl:template match="/">
<!-- The fun starts here -->
<nav id="navigation" role="navigationer" class="right">
<ul>
<xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
<!-- we're under the item - you can do your own styling here -->
<xsl:attribute name="class">selected</xsl:attribute>
</xsl:if>
<xsl:choose>
<xsl:when test="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/*[@isDoc and string(umbracoNaviHide) != '1']/navigationTitle!=''">
<xsl:value-of select="$currentPage/navigationTitle"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$currentPage/@nodeName"/>
</xsl:otherwise>
</xsl:choose>
</a>
</li>
</xsl:for-each>
</ul>
</nav>
</xsl:template>
/Dennis
Hi Dennis
Sorry, was a bit too quick on the keyboard there - just skimmed the code before. My bad...
You should be able to just make the test like this, since you're already in the context of a loop.
<xsl:choose>
<xsl:when test="navigationTitle!=''">
<xsl:value-of select="navigationTitle"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@nodeName"/>
</xsl:otherwise>
</xsl:choose>
Be aware that the navigation can be made in a better way using apply-templates though - If you have the time I think you will find this helper by Chriztian Steinmeier usefull: https://github.com/greystate/Greystate-XSLT-Helpers/tree/master/navigationhelper
Hope this helps.
/Jan
Hi Dennis,
Here's a nice way of doing that in a single line:
/Chriztian
Hi Jan and Chriztian,
Thanks for your help, I appreciate that.
It's been too long since I've been working with Umbraco :).
I think I must work with Umbraco more in my spare time :), because I love to work with the system.
So again, many thanks for your help.
/ Dennis
is working on a reply...