Copied to clipboard

Flag this post as spam?

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


  • LD 9 posts 90 karma points
    Jul 06, 2016 @ 13:05
    LD
    0

    3rd Level submenu

    Hi all, I am using Umbraco v7 Razor syntax, I try to create a 3rd level sub menu, a static example here so you can get the picture. My Umbraco code:

                        <ul class="menuzord-menu">           
                            @{
                                var maxLevelForNav = 4;   
                                var node = Umbraco.Content(1072); 
                                var home = CurrentPage.AncestorsOrSelf(1).First();
    
                                @RenderNavForNode(home, 1)
    
                                foreach (var page in home.Children.Where("Visible"))
                                {
                                    @RenderNavForNode(page, maxLevelForNav);
                                }
                            }
    
                        @helper RenderNavForNode(dynamic page, int maxLevel)
                            {
                                var current = CurrentPage.Id == page.Id ? "active" : null;
                                var node = Umbraco.Content(1072); 
                                if (page.Children.Where("Visible").Any() && page.Level == 2 )
                                {
                                    @:<li><a href="@page.Url" >@page.Name</a>
                                }
    
    
                                else
                                {
                                    @:<li><a  href="@page.Url">@page.Name</a></li>
                                }
    
    
                                if (page.Children.Where("Visible").Any() && page.Level < maxLevel )
                                {
    
                                    <ul class="dropdown">
                                        @foreach (var subPage in page.Children.Where("Visible"))
                                        {
                                            @RenderNavForNode(subPage, maxLevel)
                                        }
                                       @if (item.Children.Where("Visible").Count() > 0)
                                       {
                                        foreach (var subPage in page.Children.Where("Visible"))
                                        {
                                          @:<li><a  href="@subPage.Url">@subPage.Name</a></li>
                                        }                                          
                                       }
    
                                    </ul> 
                                }
                            }
                        </ul>
    

    I can't make the 3rd level submenu :( can you please assist? Thank you!!

  • Sagar 74 posts 275 karma points
    Jul 07, 2016 @ 08:27
    Sagar
    1

    Hii LD,

    here ia the code for multi level menus

    @{ 
        var site = CurrentPage.Site();
        if (site != null) {
            <ul>
                <li class="@(CurrentPage.Id == site.Id ? "selected" : "")"><a href="@(site.Url)">@site.Name</a></li>
                @traverse(site)
            </ul>         
        }
    }                                                      
    
    @helper traverse(dynamic parent)
    {
        <ul>
            @foreach (IPublishedContent node in parent.Children.Where("Visible"))
            {                
                    <li>
                        <a class="@(CurrentPage.Id == node.Id ? "selected" : "")" href="@node.Url">@node.Name</a>                                       
                        @traverse(node)
                    </li>            
            }
        </ul>                                                            
    }
    

    Hope this will help you.. Cheers Sagar..!

  • Hitesh CHauhan 2 posts 71 karma points
    Jul 27, 2019 @ 03:45
    Hitesh CHauhan
    0

    thanks

  • Hitesh CHauhan 2 posts 71 karma points
    Jul 24, 2019 @ 14:14
    Hitesh CHauhan
    0
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies