Copied to clipboard

Flag this post as spam?

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


  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jun 18, 2010 @ 21:43
    Bo Damgaard Mortensen
    0

    xslt menu problems

    Hi fellow umbraco users,

    I'm currently building a website based on umbraco and I ran into some problems with my main navigation.

    My current structure is something like:

    • - Content
    •        - Frontpage (Forside)
    •                 - Profile (Profil)
    •                 - References (Referencer)
    •                 - Contact (Kontakt)

    So as you can see, the Profile, References and Contact pages are children of the Frontpage - all pages are using the same document type.

    You can see the site here: http://www.nuanceweb.dk

    What I want is, that the menu item you've clicked should be marked as active (the light grey color) and for now it works with the pages Profil, Referencer and Kontakt, but not the front page.

    My XSLT looks like this:

    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=1]/node">
     <a href="{umbraco.library:NiceUrl(@id)}"> 
      <li class="menuItem">   
       <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
                   <xsl:attribute name="class">activeMenuItem</xsl:attribute>
               </xsl:if>  
       <div style="padding-top:7px;">
        <xsl:value-of select="@nodeName" />  
       </div>
      
      </li> 
     </a>
    </xsl:for-each>

    ... and the 'Forside' link is hardcoded at the moment.

    Is there a better way to do this? It seems quite hard for me to make the 'Forside' page a part of this for-each loop as it is the parent node of the collection i'm looping through.

    Any suggestions on this one? Or should I be re-structuring my site completely in order to make this? I'm still learning umbraco as I've made a change from PHP (Joomla!) to Umbraco.

    Thanks a lot in advance!

    / Bo

  • MartinB 411 posts 512 karma points
    Jun 18, 2010 @ 22:09
    MartinB
    0

    Hi Bo

    I suggest that you build your site like this:

    - Site name

       - Forside

       - Page number 2

       - Page number 3

    etc.. thus keeping your frontpage link on the same level as your subpages and thus cutting out a level.

    I use this XSLT to do the same you're trying to acomplish:

    <?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="topMenu">
    <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">
    <xsl:attribute name="class">current</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@nodeName"/>
    </a>
    </li>
    </xsl:for-each>
    </ul>

    </xsl:template>

    </xsl:stylesheet>
  • MartinB 411 posts 512 karma points
    Jun 18, 2010 @ 22:11
    MartinB
    0

    Take a look at www.fairlux.dk - there i think i do what you're looking for with the above structure

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jun 18, 2010 @ 23:50
    Bo Damgaard Mortensen
    0

    Hey Martin,

    Thanks for the answer! -and nice site you've got there :) That is exactly what I need for my menu.

    I tried refactoring my structure, so now it's like this:

     

    • - Content
    •        - Forside
    •        - Profil
    •        - Referencer
    •        - Kontakt

    So, now all the pages are on the same level (which I guess is level 1?) I tried to use the exact same xslt code that you're using, but sadly my menu has disappeared. Of course, I've changed it to use my active-link style instead ;)

    I'll keep toying around with it though! It's good fun and a time-stealer.

    Just as a side question really: how do you go about forwarding to your 'forside.aspx' when you enter www.fairlux.dk? I'd know exactly how if it were joomla, but it seems that the learning-curve in umbraco is a tad more steep than what I'm used to. Doesn't matter though, it's a great challenge :)

    Thanks again,

    Bo 

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jun 19, 2010 @ 00:30
    Bo Damgaard Mortensen
    1

    Got it to work now by doing as you wrote (need to read what people actually write ;))

    The structure is now:

    • - Content
    •         - Site name
    •                   - Forside
    •                   - Profil
    •                   - Referencer
    •                   - Kontakt

    Only thing I'm not sure about now is, how I'm able to tell umbraco that when people are entering: www.thesite.com - it needs to automatically go to www.thesite.com/frontpage.aspx (else the menu won't display because there's no node)

    Anyone know how to do this? I bet it's very, very simple ;) Just can't find it..

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jun 19, 2010 @ 00:49
    Bo Damgaard Mortensen
    0

    Found the solution to this thanks to a few minutes with google ;)

    I added a property to the document type for what would be the "Site name" page in my last post. The property type alias should be called umbracoRedirect and the type should be a content picker. Then you're able to pick the page ('Forside' in my case) that should be redirected to. Pretty neat!

    Just in case anyone with the same problem steps by this thread.

  • MartinB 411 posts 512 karma points
    Jun 19, 2010 @ 00:51
    MartinB
    0

    Hi Bo

    Glad you got it working :-), but actually my Fairlux structure is like this:

    - Fairlux.dk

       - Forside

       - Næste menupunkt

       - etc

    It might be a level setting in the xslt that makes your menu disappear. Se:

    <xsl:variable name="level" select="1"/>

    You tell the page to redirect to the "frontpage.aspx" by adding the umbracoRedirect property to your templates. See this reference:

    http://our.umbraco.org/wiki/reference/umbraco-best-practices/umbracoredirect

    Don't mind the warning described in the text and your set to go! :-)

  • MartinB 411 posts 512 karma points
    Jun 19, 2010 @ 00:52
    MartinB
    0

    Ok, you found it in the meantime. Good :-)

  • MartinB 411 posts 512 karma points
    Jun 19, 2010 @ 00:56
    MartinB
    0

    Ok... big DOH here,

    Ofcourse my menu is like:

    - Content

       - Site name

          - Subpage name

    Glad you figured that out, my bad :-)

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jun 19, 2010 @ 16:04
    Bo Damgaard Mortensen
    0

    All good! ;) Figured out what you mean't anyway hehe.

    Thanks a lot for your help! It's greatly appreciated :)

    Mvh. Bo

Please Sign in or register to post replies

Write your reply to:

Draft