Copied to clipboard

Flag this post as spam?

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


  • Michael Jensen 29 posts 98 karma points
    Nov 28, 2015 @ 16:46
    Michael Jensen
    0

    Dropdown Topnavigation problem.

    Hey.

    iam tryning to get the following topnavination menu convertede to a XSLT dut iam not so dam good in version 7 yet.

    this is the one i use in my version 6 site in the scripting files.

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
        @{
            @*Get the toot og the website *@
            var root = Model.AncestorOrSelf(1).Children.Where("Visible");
        }
    <ul>
        <li><a href="/">FORSIDE</a></li>
        @foreach (var page in root)
        {
            <li class="@page.IsAncestorOrSelf(Model, "current-menu-item", "")">
                <a href="@page.Url">@page.Name</a>
                @* check if page has chrildren *@
                @if (page.Children.Where("Visible").Count() > 0)
                {
                        <ul>
                            @foreach (var subpage1 in page.Children.Where("Visible"))
                            {
                                <li>
                                    <a href="@subpage1.Url">@subpage1.Name</a>
                                    }
                                </li>
                            }
                        </ul>
                }
            </li>
        }
    </ul>
    

    I love to get it over to XSLT. and i dit try but i cant get it to work.

    <?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:Examine="urn:Examine" 
        exclude-result-prefixes="msxml umbraco.library Examine ">
    
    
    <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 class="nav navbar-nav navbar-right">
            <li>
                <a href="#" class="" data-toggle="dropdown">Velkommen</a>
            </li>
            <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '0']">
                <li class="dropdown">
                    <a href="{umbraco.library:NiceUrl(@id)}" class="dropdown-toggle" data-toggle="dropdown"><xsl:value-of select="@nodeName"/></a>
                    <ul class="dropdown-menu">
                        <li class="">
                            <a href="{umbraco.library:NiceUrl(@id)}" class="dropdown-toggle" data-toggle="dropdown"><xsl:value-of select="@nodeName"/></a>
                        </li>                                                           
                    </ul>
                </li>
            </xsl:for-each>
    
    
    
    </ul>
    </xsl:template>
    
    </xsl:stylesheet>
    

    i hope som can help me..

    i noly need it to list subpages one lvl down

    like this.

    page pagesub

    Michael

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Nov 28, 2015 @ 18:19
    Dennis Aaen
    100

    Hi Michael,

    Since you are using Umbraco 7 I can help you convert it to a partial view or partial view macro file.

    Try to use this code below

        @{
            @*Get the toot og the website *@
            var root = CurrentPage.AncestorOrSelf(1).Children.Where("Visible");
        }
    <ul>
        <li><a href="/">FORSIDE</a></li>
        @foreach (var page in root)
        {
            <li class="@page.IsAncestorOrSelf(CurrentPage, "current-menu-item", "")">
                <a href="@page.Url">@page.Name</a>
                @* check if page has chrildren *@
                @if (page.Children.Where("Visible").Any())
                {
                        <ul>
                            @foreach (var subpage1 in page.Children.Where("Visible"))
                            {
                                <li>
                                    <a href="@subpage1.Url">@subpage1.Name</a>
                                    }
                                </li>
                            }
                        </ul>
                }
            </li>
        }
    </ul>
    

    If you are using Partial view then you need to add this in the top of the file,

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    

    Try to see this documentation https://our.umbraco.org/documentation/Reference/Templating/Mvc/partial-views

    If you are using a Partial view macro file, then you would need to add this to the top of the file.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    

    Try to see the documentation here https://our.umbraco.org/documentation/Reference/Templating/Macros/Partial-View-Macros/ and https://our.umbraco.org/documentation/Reference/Templating/Mvc/views

    Hope this helps,

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft