Copied to clipboard

Flag this post as spam?

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


  • Fredrik Esseen 610 posts 906 karma points
    Sep 17, 2009 @ 16:07
    Fredrik Esseen
    0

    Set MenuItem as Selected when Subnode is selected

    Hi!

    Im using the Runway Topnavigation to display my top nodes.

    Ive created a submenu and now wants the Top Parent node in the RunwayTopNavigation to be selected so its easy to see under which section the user is.

    Today my xslt looks like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <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"/>
    <!-- Input the documenttype you want here -->
    <xsl:variable name="level" select="1"/>
    <xsl:template match="/">
    <!-- The fun starts here -->
    <ul id="topnavigation">
    <!-- <xsl:choose>
      <xsl:when test="$currentPage/@id='1055'"> 
        <div class="MenuItemSelected">
         <li>
         <div class="MenuLinkText">
         <a href="hem.aspx">Startsidan</a>
          </div>
         </li>
        </div>
       </xsl:when>
       <xsl:otherwise>
        <div class="MenuItem">
         <li>
         <div class="MenuLinkText">
          <a href="hem.aspx">Startsidan</a>
         </div>
         </li>
        </div>
       </xsl:otherwise>
      </xsl:choose>-->
    <!--<li><a href="/">Hem</a></li>-->
    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [@nodeTypeAlias != 'Nyheter'][string(data [@alias='umbracoNaviHide']) != '1' and @nodeName != 'Kundsidor']">
     
      <xsl:choose>
       <xsl:when test="$currentPage/@id=@id"> 
        <div class="MenuItemSelected">
         <li>
         <div class="MenuLinkText">
          <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
          </a>
         </div>
         </li>
        </div>
        
        </xsl:when>
        <xsl:otherwise>
        <div class="MenuItem">
         <li>
         <div class="MenuLinkText">
          <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
          </a>
         
         </div>
         </li>
        </div>
        </xsl:otherwise>
     
      </xsl:choose>
      
     
    </xsl:for-each>
    </ul>
    </xsl:template>
    </xsl:stylesheet>

     

    This way I can change the layout for the selected item, but only in the first level.

  • Tim 225 posts 690 karma points
    Sep 17, 2009 @ 17:33
    Tim
    0

    Hi,

    It may be worth looking at this navigation package, which supports this out of the box:

    http://our.umbraco.org/projects/cogworks---flexible-navigation

    T

  • Fredrik Esseen 610 posts 906 karma points
    Sep 18, 2009 @ 14:27
    Fredrik Esseen
    0

    Of course I could have used it but since I styled my menu so nice I didnt want to start over with css:ing :)

    It was quite easy actually I changed the for-each like this:

    <xsl:when test="$currentPage/@id=@id or $currentPage/ancestor-or-self::node/@id=@id"> 

    Worked like a charm!

Please Sign in or register to post replies

Write your reply to:

Draft