Copied to clipboard

Flag this post as spam?

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


  • Amigo 243 posts 568 karma points
    Dec 15, 2010 @ 18:30
    Amigo
    0

    top menu in subfolder

    Hey,

    I have a menu xslt (shown last in this post)

    My problem is that i have some pages created in a subfolder.
    When view theese subfolder pages, only my frontpage link is shown.
    I wish to make all my root nodes show in the menu
    Any ideas to a solution?

    <?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" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"  exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
        <xsl:output method="xml" omit-xml-declaration="yes" />
        <xsl:param name="currentPage"/>
        <!-- Input the documenttype you want here -->
        <!-- Typically '1' for topnavigtaion and '2' for 2nd level -->
        <!-- Use div elements around this macro combined with css -->
        <!-- for styling the navigation -->
        <xsl:variable name="level" select="1"/>
        <xsl:template match="/">
            <!-- The fun starts here -->
            <ul>
                <li>
                    <a href="/" >
                        <xsl:if test="$currentPage/@nodeName = FrontPage'">
                            <xsl:attribute name="class">selected</xsl:attribute>
                            <xsl:attribute name="title">Forsiden</xsl:attribute>
                        </xsl:if>
                        Forsiden  
                    </a>
                </li>
                <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:attribute name="title">
                                <xsl:value-of select="@nodeName"/>
                            </xsl:attribute>
                            <xsl:value-of select="@nodeName"/>
                        </a>
                    </li>
                </xsl:for-each>
            </ul>
        </xsl:template>
    </xsl:stylesheet>

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 15, 2010 @ 18:56
    Kim Andersen
    0

    Hi Amigo

    Could you show us your content structure? The code you provided above, should show a menu that lists the nodes on level 2 (the children of level 1) and also a link to the frontpage.

    /Kim A

  • Amigo 243 posts 568 karma points
    Dec 15, 2010 @ 19:46
    Amigo
    0

    Hi Kim,

    I just have a empty masterpage that my layoutmasterpage inherit from.
    My layoutmasterpage includes the topmenu as a macro:
    <umbraco:Macro Alias="Navigation" runat="server"></umbraco:Macro>

    My subpagemasterpage, (the one used for my pages, also the pages in my subfolder not showing the topmenu), inherit from my layoutmasterpage.

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 15, 2010 @ 20:02
    Kim Andersen
    0

    I was thinking of your node structure in the Content section. How did you set up the nodes? Eg.:

    - Content (The default root node in the content section)
      - Home
        - Page 1
        - Page 2
          - Subpage 1
          - Subpage 2
        - Page 3

    Or:

    - Content (The default root node in the content section)
      - Home
      - Page 1
      - Page 2
        - Subpage 1
        - Subpage 2
      - Page 3

    Or how is it structured?

    /Kim A

  • Amigo 243 posts 568 karma points
    Dec 15, 2010 @ 20:02
    Amigo
    0

    content structure is:

    home
       subpage1
       subpage2

    folder
       subsubpage1 (should show: home, subpage1, subpage2) in menu but dont

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 15, 2010 @ 20:17
    Kim Andersen
    0

    The reason why the code doesn't show any other link but the homepage link is this:

    This for-each:

    <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">

    Will go from the current page (the subsubpage1) and then go all the way up in the tree until it hits a node on level 1 (this will be the "folder"-node). And when that node is found, it will run through all the childnodes of that node (in this case the only childnode is subsubpage1). The reason why the link to the homepage is rendered is that it's hardcoded in the xslt file. Acually the subsubpage1 should also be shown in the menu next to the Forsiden-link, unless the subsubpage1 has the umbracoNaviHide set to true.

    But actually this is kind of an atypical way of structuring the content. Normally what most people do is to structure the content like this:

    - Content (The default root node in the content section)
      - Home
        - Subpage 1
        - Subpage 2
        - Folder
          - Subsubpage1

    If this is the structure you will get a navigation showing (home, subpage1, subpage2 and also Folder unless you set the umbracoNaviHide to true). Maybe you should consider restructuring your content so that most of your future coding will be a lot easier. Not only thinking about your top menu, but also thinking about subnavigations, breadcrumb etc.

    /Kim A

  • Amigo 243 posts 568 karma points
    Dec 15, 2010 @ 20:49
    Amigo
    0

    Cool, i changed my structure and things are just fine.

    Thanks a lot Kim ;-)

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 16, 2010 @ 00:41
    Kim Andersen
    0

    No problem Amigo.

    As said in my earlier post, that way of structuring the content is the most common way of doing it. And the predefined XSLT templates that's found in Umbraco is also build for this kind of structure, so when you are using them it helps a lot when the structure is the same :)

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft