Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 01, 2012 @ 15:46
    Dennis Aaen
    0

    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.

    <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.

    /Dennis

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Sep 01, 2012 @ 15:54
    Jan Skovgaard
    0

    Hi Dennis

    You need to write the $currentPage/....stuff before the "navigationTitle" in the value-of :)

    /Jan

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 01, 2012 @ 16:04
    Dennis Aaen
    0

    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

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Sep 01, 2012 @ 16:14
    Jan Skovgaard
    1

    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

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Sep 01, 2012 @ 16:16
    Chriztian Steinmeier
    2

    Hi Dennis,

    Here's a nice way of doing that in a single line:

    <xsl:variable name="navRoot" select="$currentPage/ancestor-or-self::*[@isDoc][@level = $level]" />
    
    <xsl:template match="/">
        <nav id="navigation" role="navigation" class="right">  
            <ul>
                <xsl:for-each select="$navRoot/*[@isDoc and not(umbracoNaviHide = 1)]">
                    <li>
                        <a href="{umbraco.library:NiceUrl(@id)}">
                            <xsl:if test="descendant-or-self::*[@id = $currentPage/@id]">
                                <xsl:attribute name="class">selected</xsl:attribute>
                            </xsl:if>
                            <!-- Take navigationTitle - fallback to @nodeName if empty --> <xsl:value-of select="(@nodeName[not(normalize-space(../navigationTitle))] | navigationTitle)[1]" />
                        </a>
                    </li>
                </xsl:for-each>
            </ul>
        </nav>
    </xsl:template>

    /Chriztian

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 01, 2012 @ 16:26
    Dennis Aaen
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft