Copied to clipboard

Flag this post as spam?

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


  • Vincent Ashby-Smith 67 posts 196 karma points
    Jun 08, 2015 @ 17:46
    Vincent Ashby-Smith
    0

    Hide level 3 show level 4 items in navigation

    Hi all, not sure if this has been asked before (i've looked through many forum posts but can't find anything!). I basically want to show a navigation item at level 4 but hide the item at level 3, using UmbracoNaviHide.

    This is my code which is used to draw out the navigation:

    @foreach (var subMenuItem in subMenuItems)
    {
        <ul class="col-md-3">
            <li><a href="@subMenuItem.Url" title="@subMenuItem.Name" class="navigation-heading">@subMenuItem.Name</a></li>
            @if (subMenuItem.Children.Where("UmbracoNaviHide == false").Any())
            {
                @* Call our helper to display the children *@
                @SubMenuChildItems(subMenuItem.Children)
            }
        </ul>
    }
    
    @helper SubMenuChildItems(dynamic subMenuChildItems)
    {
        var childItems = subMenuChildItems.Where("UmbracoNaviHide == false");
    
        @* Ensure that we have a collection of Sub Menu Child Items *@
        if (childItems.Any())
        {
            <li>
                <ul>
                    @foreach (var childItem in childItems)
                    {
                        <li>
                            <a href="@childItem.Url">@childItem.Name</a>
    
                            @* if the current Sub Menu Child Item has any children, where the property umbracoNaviHide is not True *@
                            @if (childItem.Children.Where("UmbracoNaviHide == false").Any())
                            {
                                @* Call our helper to display the children *@
                                @SubMenuChildItems(childItem.Children)
                            }
                        </li>
                    }
                </ul>
            </li>
        }
    }
    
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jun 08, 2015 @ 21:13
    Dennis Aaen
    0

    Hi Vincent,

    Does it works if you do it like this instead.

    @foreach (var subMenuItem in subMenuItems)
    {
        <ul class="col-md-3">
            <li><a href="@subMenuItem.Url" title="@subMenuItem.Name" class="navigation-heading">@subMenuItem.Name</a></li>
            @if (subMenuItem.Children.Where("Visible").Any())
            {
                @* Call our helper to display the children *@
                @SubMenuChildItems(subMenuItem.Children)
            }
        </ul>
    }
    
    @helper SubMenuChildItems(dynamic subMenuChildItems)
    {
        var childItems = subMenuChildItems.Where("Visible");
    
        @* Ensure that we have a collection of Sub Menu Child Items *@
        if (childItems.Any())
        {
            <li>
                <ul>
                    @foreach (var childItem in childItems)
                    {
                        <li>
                            <a href="@childItem.Url">@childItem.Name</a>
    
                            @* if the current Sub Menu Child Item has any children, where the property umbracoNaviHide is not True *@
                            @if (childItem.Children.Where("Visble").Any())
                            {
                                @* Call our helper to display the children *@
                                @SubMenuChildItems(childItem.Children)
                            }
                        </li>
                    }
                </ul>
            </li>
        }
    }
    

    Hope this helps,

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft