Copied to clipboard

Flag this post as spam?

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


  • Phil Crowe 192 posts 256 karma points
    Apr 01, 2010 @ 18:32
    Phil Crowe
    0

    change item in top nav

    Hi, i have a top nav made in xslt and i want one of the nodes in the top nav to display a different name to what its actual page name is. Ive looked at xsl choose but can only find example of change the href or title of the node. Can you help me please????

     

     

  • webangelo 107 posts 190 karma points
    Apr 01, 2010 @ 19:21
    webangelo
    0

    Hi Phil,

    I can't tell from your question whether this alternate name is stored in the data or hardcoded.  Assuming you have a navigation similar to this:

    <ul id="topNav">
    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
        <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
            </a>
        </li>
    </xsl:for-each>
    </ul>

    If you want to hard-code it you can change it to something like this. (Where nameToChange is the name of the link you want to change)

    <ul id="topNav">
    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
        <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:choose>
                    <xsl:when test="@nodeName = 'nameToChange'">
                        New Name
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="@nodeName"/>
                    </xsl:otherwise>
                </xsl:choose>
            </a>
        </li>
    </xsl:for-each>
    </ul>

    If using another field you can either use the above and replace New Name with:

     <xsl:value-of select="data [@alias='newFieldName']"/>
  • webangelo 107 posts 190 karma points
    Apr 01, 2010 @ 19:26
    webangelo
    0

    BTW, my example above is a local nav structure.  The Top Nav would be closer to this if you use the built-in Navigation XSLT pattern:

    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']">
        <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
                    <!-- we're under the item - you can do your own styling here -->
                    <xsl:attribute name="style">font-weight: bold;</xsl:attribute>
                </xsl:if>
                <xsl:choose>
                   
    <xsl:when test="@nodeName = 'nameToChange'">
                        New Name
                   
    </xsl:when>
                   
    <xsl:otherwise>
                       
    <xsl:value-of select="@nodeName"/>
                   
    </xsl:otherwise>
               
    </xsl:choose>
            </a>
        </li>
    </xsl:for-each>
  • Paul Blair 466 posts 731 karma points
    Apr 01, 2010 @ 21:51
    Paul Blair
    0

    Hi Phil,

    I add an optional property to my documents and when it is populated I use that for the menu title. The XSLT then looks like:

            <xsl:choose>
              <xsl:when test="string(./data [@alias='MenuTitle'])=''">
                <xsl:value-of select="./@nodeName" />
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="./data [@alias='MenuTitle']" />
              </xsl:otherwise>
            </xsl:choose>

    Cheers

    Paul

Please Sign in or register to post replies

Write your reply to:

Draft