Copied to clipboard

Flag this post as spam?

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


  • Amir Khan 1287 posts 2744 karma points
    Feb 09, 2011 @ 20:53
    Amir Khan
    0

    Old to New navigation when / otherwise situation

    So i'm using one of the navigation templates for the New XSLT Schema, the code is as follows:

     <ul>
           <li>
             <xsl:if test="$currentPage/@id = $currentPage/ancestor-or-self::* [@level=$level]/@id">
                 <xsl:attribute name="class">home active</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>
         <xsl:if test="@id = $currentPage/@id">
            <xsl:attribute name="class">active</xsl:attribute>
          </xsl:if>
        <a class="navigation" href="{umbraco.library:NiceUrl(@id)}">
          <span><xsl:value-of select="@nodeName"/></span>
        </a>
      </li>
      
      
    </xsl:for-each>
    </ul>

    What I'm trying to achieve, is that if one of the nav items is of a certain document type "ExternalLink" instead of linking the a href to the {umbraco.library:NiceUrl...} I'd like it to pull the link from a field i've added to the document type called "externalLinkAddress"

    I believe i could so something like "data [@alias = 'externalLinkAddress']" for the link, i'm just not sure how to apply the "when" statement"

    <xsl:choose>
     
    <xsl:when test="$ExternalLink">
     

    <li>
         <xsl:if test="@id = $currentPage/@id">
            <xsl:attribute name="class">active</xsl:attribute>
          </xsl:if>
        <a class="navigation" href="{umbraco.library:NiceUrl(@id)}">
          <span><xsl:value-of select="@nodeName"/></span>
        </a>
      </li> </xsl:when>
     
    <xsl:otherwise>
     

    <li>
         <xsl:if test="@id = $currentPage/@id">
            <xsl:attribute name="class">active</xsl:attribute>
          </xsl:if>
        <a class="navigation" href="data [@alias = 'externalLinkAddress']">
          <span><xsl:value-of select="@nodeName"/></span>
        </a>
      </li> </xsl:otherwise>
    </xsl:choose>

    Any help would be appreciated!


    Thank you,

    Amir

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Feb 09, 2011 @ 21:02
    Chriztian Steinmeier
    1

    Hi Amir,

    Try something like this:

    <ul>
        <li>
            <xsl:if test="$currentPage/@id = $currentPage/ancestor-or-self::* [@level=$level]/@id">
                <xsl:attribute name="class">home active</xsl:attribute>
            </xsl:if>
            <a href="/">Home</a>
        </li>
    
        <xsl:for-each select="$currentPage/ancestor-or-self::*[@level = $level]/*[@isDoc and not(umbracoNaviHide = 1)]">
            <li>
                <xsl:if test="@id = $currentPage/@id">
                    <xsl:attribute name="class">active</xsl:attribute>
                </xsl:if>
                <a class="navigation">
                    <xsl:attribute name="href">
                        <xsl:choose>
                            <!-- Is this an ExternalLink document? -->
                            <xsl:when test="self::ExternalLink">
                                <xsl:value-of select="externalLinkAddress" />
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="umbraco.library:NiceUrl(@id)" />
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:attribute>
                    <span><xsl:value-of select="@nodeName"/></span>
                </a>
            </li>
        </xsl:for-each>
    </ul>

    /Chriztian

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 09, 2011 @ 21:12
    Jan Skovgaard
    0

    Hi Amir

    If you're making use of the new schema the code in your second sample will not work since there is no data element in the umbraco.config file anymore.

    Try this out and see if this works

    <li>
         <xsl:if test="@id = $currentPage/@id">
            <xsl:attribute name="class">active</xsl:attribute>
          </xsl:if>

    <xsl:choose>
     <xsl:when test="$ExternalLink">
     
        <a class="navigation" href="externalLinkAddress">
          <span><xsl:value-of select="@nodeName"/></span>
        </a>

     <xsl:otherwise>
     
        <a class="navigation" href="{umbraco.library:NiceUrl(@id)}">
          <span><xsl:value-of select="@nodeName"/></span>
        </a>
       </xsl:when>
     </xsl:otherwise>
    </xsl:choose>
    </li>

    A few comments

    I moved the <xsl:choose> inside your <li></li> element so you only need to make the test for setting the active class once.

    I also guess you by mistake have switched the two links around? You need to get the value from the externalLinkAdress when there is something in it, right?

    Try it out and see if it works for you :-)

    /Jan

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 09, 2011 @ 21:15
    Jan Skovgaard
    0

    Wow...was way to slow there :-)

    /Jan

  • Amir Khan 1287 posts 2744 karma points
    Feb 09, 2011 @ 21:22
    Amir Khan
    0

    Hi Jan,

    Chriztian's code above worked perfectly, I was getting some errors with your code when I tried, not sure why? I appreciate your help regardless, I find it useful to see different ways to acheive a similar thing, always comes in handy somewhere down the line.

    Thanks!

    Amir

Please Sign in or register to post replies

Write your reply to:

Draft