Copied to clipboard

Flag this post as spam?

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


  • Sagar 74 posts 275 karma points
    Jun 03, 2016 @ 12:32
    Sagar
    0

    Dynamic Menus with Dynamic Level

    How to create Dynamic Menus with Dynamic Child Levels??.

  • MuirisOG 382 posts 1284 karma points
    Jun 03, 2016 @ 13:11
    MuirisOG
    1

    Log into the Umbraco backend, then select the Settings section, and then select a template to edit.

    The editing area for the template has an icon which allows you to insert an inline razor macro, which has a few options for adding menus.

  • Sagar 74 posts 275 karma points
    Jun 08, 2016 @ 04:10
    Sagar
    0

    Can u please Elaborate provide Code for it

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Jun 08, 2016 @ 07:48
    Dennis Adolfi
    100

    Hi Sagar.

    I might be wrong, but it sounds like you are looking for a menu that uses a traverse method helper to iterate children and create a dynamic menu?

    Could this work for you?

    @{ 
        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>                                                            
    }
    
  • Sagar 74 posts 275 karma points
    Jun 08, 2016 @ 08:53
    Sagar
    1

    Thnxx Dennis it worked, but having some allignment issue which i will be fixing

    Thnxx for the reply..

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Jun 08, 2016 @ 09:01
    Dennis Adolfi
    1

    Great! Glad to help!!

    Yeah, it probobly needs som Css-lovin to make it look pretty, but that should be a quick fix.

    Take care, best of luck with the rest of the site!

    / Dennis

  • MuirisOG 382 posts 1284 karma points
    Jun 17, 2016 @ 09:44
    MuirisOG
    0

    Apologies Sagar

    I thought you were looking for something like this (which is inserted into your template, as described in my first post).

    Note: this is generated for WebForms sites, and MVC will look a little different.

    <umbraco:Macro  runat="server" language="cshtml">
    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @*
        Macro to display child pages below the root page of a standard website.
        Also highlights the current active page/section in the navigation with
        the css class "current". 
    *@
    
    @{ 
        @* Get the root of the website *@
        var root = Model.AncestorOrSelf(1);
    }
    
    <ul>
        @foreach (var page in root.Children.Where("Visible"))
        { 
            <li class="@page.IsAncestorOrSelf(Model, "current", "")">
                <a href="@page.Url">@page.Name</a>
            </li>
        }
    </ul>
    
    </umbraco:Macro>
    
Please Sign in or register to post replies

Write your reply to:

Draft