Copied to clipboard

Flag this post as spam?

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


  • Søren H. Pedersen 15 posts 65 karma points
    Jul 11, 2014 @ 20:37
    Søren H. Pedersen
    0

    Navigation with a Child Navigation

    Hello there

    Just recently started working with Umbraco and after fooling around with umbraco 7, I've started to really fall in love with how it works. But I've run into a problem with how the coding works and been trying to throw it around, and so fare to no effect

    The site I am working on's code, is based upon the starterkit ones along with other guides I've found (allot of them however where for older version of Umbraco so where of little help). So fare, the page setup is like this:

    Home

    -> TextPage1

    -> TextPage2

    ---->SubTextPage1

    -> TextPage3

    The file is in Partial View, and I've been able to show both the TextPages and the SubTextPages, however, I want the SubTextPage to be shown, only when the parent page is selected, and stay visible until the parent page is left.

        var homePage = CurrentPage.AncestorsOrSelf(1).First();
        var menuItems = homePage.Children.Where("UmbracoNaviHide == false");
    }
    <!-- Nav -->
    <ul class="menu">
        @foreach (var item in menuItems)
        {
            var childrenItems = item.Children.Where("UmbracoNaviHide == false");
            <li class="@(CurrentPage.Id == item.Id ? "sel" : null)">
                @createSubmenu(childrenItems, item.Id)
            </li>
        }
    </ul>
    
    @helper createSubmenu(IEnumerable<IPublishedContent> nodes, int? parentId) 
    {
        if (nodes.Count() > 0){
            <ul>
            @foreach (var node in nodes)
            {
                var childrenItems = node.Children.Where("UmbracoNaviHide == false");
                <li class="@(CurrentPage.Id == node.Id ? "sel" : null)">
                    <a href="@node.Url">@node.Name</a>
                </li>
            }
            </ul>
        }
    }
    <!-- /Nav -->
    

    Kind Regards Søren

Please Sign in or register to post replies

Write your reply to:

Draft