Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 25, 2012 @ 13:37
    Fuji Kusaka
    0

    Converting XSLT Navi toRazor

    Hi Guys,

    I have a main navigation with 2 level (drop down menu). What am trying to do is something like when clicking on the 2nd level link navi i get the first level showing this section is selectet or (current) in my case.

    My XSLT looks like this 

     <xsl:if test="$currentPage/ancestor-or-self::*[@isDoc]/@id = current()/@id">
                                           <xsl:text> current</xsl:text>
                                        </xsl:if>

    And Razor

    <li>             {
                        <a href="@page.Url" class="@Library.If(page.Id == Model.Id, "current", "")">@page.Name</a>
                    }
                                  <!--  (2nd Level or drop down-->
                    @if (page.children.Where("Visible").Count() > 0)
                    {
                        <ul>
                            @foreach (var childPage in page.Children.Where("Visible"))
                            {
                                <li><a href="@childPage.Url">@childPage.Name</a></li>
                            }
                        </ul>
                    }
                </li>

    Any help on this?

    //fuji

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jan 26, 2012 @ 09:45
    Dan Diplo
    0

    Here's an example of how I do a top level nav using the IsAncestorOrSelf method of a DynamicNode. It should help you:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using umbraco.MacroEngines;
    
    @{
        var pages = Model.AncestorOrSelf(1).Children.Where("Visible && template > 0");
        const string selectedClass = " class=\"current\"";
        bool hasSubNav = true;
    
        <ul id="nav">
    
            <[email protected](Model.NodeTypeAlias == "Home", selectedClass)>
               <a href="/">Home</a>
            </li>
    
            @if (pages.Count() > 0)
            {
                foreach (dynamic page in pages)
                {                 
                    <[email protected](page.IsAncestorOrSelf(Model), selectedClass)>
                        <a href="@page.Url">@page.Name</a>
                        @if (hasSubNav)
                        {
                            @RenderSubNav(page, selectedClass)
                        }
                    </li>
                }
            }
        </ul>
    }
    
    @helper RenderSubNav(dynamic parent, string selectedClass)
    {
        var pages = parent.Children.Where("Visible && template > 0");
    
        if (pages.Count() > 0)
        {
          <ul>
            @foreach (dynamic page in pages)
            {
                <[email protected](Model.Id == page.Id, selectedClass)>
                    <a href="@page.Url">@page.Name</a>
                </li>
            }
          </ul>
        }
    }

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 26, 2012 @ 10:22
    Fuji Kusaka
    0

    Hi Dan,

    Thanks for the response, ill give this a try and let you know.

    //fuji

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 26, 2012 @ 18:26
    Fuji Kusaka
    0

    Hi Dan,

    I try to understand and at same modify my razor file but on saving am getting this error message.

    No overload for method 'If' takes 2 arguments

    I even copy > paste your code but without success having the same error.

     

    //fuji

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jan 26, 2012 @ 21:17
    Dan Diplo
    0

    Hi Fuji,

    My code, as pasted, definitely works in Umbraco 4.7.1

    Are you using 4.7.1 or higher, because I think Library.If method was only introduced in that version?

    If you are, could you post your script as it must be something in that?

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 27, 2012 @ 04:17
    Fuji Kusaka
    0

    Dan am running on V4.7.0.

    I guess that what giving errors??

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 27, 2012 @ 06:46
    Fuji Kusaka
    0

    Dan i just overwrite my umbraco.MacroEngines.dll.

    I think it should get me working .

     

     

     

     

     

Please Sign in or register to post replies

Write your reply to:

Draft