Copied to clipboard

Flag this post as spam?

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


  • Mike Dorst 53 posts 215 karma points
    Nov 07, 2017 @ 10:16
    Mike Dorst
    0

    Navigation bar dissapears

    Hey,

    I am trying to make a navigation bar. My folder structure is as followed:

    Site Structure

    This is what I have right now:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    <div class="well well-lg span-padding extra-padding top background-light">
                        <div>
                            <ul class="nav nav-list tree">
                                @{                                  
                                    var documentRootNodeId = Model.Content.GetPropertyValue("documentRoot", true); // Fetch recursive document root id.
                                    var selection = Umbraco.TypedContent(documentRootNodeId).Children.Where("Visible"); // Select all nodes below the document root.
                                }
    
                                @foreach(var item in Model.Content.Descendants("menu")){
                                    foreach (var Menus in @item.Descendants("menuItem")){
                                        <li class="MenuItems">@Menus.Name</li>  
                                            foreach (var MenuItems in @Menus.Children){
                                                if(MenuItems.GetPropertyValue("hoofdstukIcoon") != "") {
                                                <li><a href="@MenuItems.Url"><i class="fa fa-@(MenuItems.GetPropertyValue("hoofdstukIcoon")) fa-fw"></i> @MenuItems.Name</a></li>
                                                    }else {
                                                            <li><a href="@MenuItems.Url">@MenuItems.Name</a></li>
    
    
                                                var childIsActive = false;
    
                                                    foreach(var sub in @MenuItems.Children){
                                                    if (CurrentPage.Url == sub.Url) {
                                                        childIsActive = true;
                                                    }
    
    
    
                                            <ul class="nav subnav nav-list tree @(childIsActive ? "" : "collapse")">
                                                @foreach(var sub2 in @MenuItems.Children){
                                                    <li @(CurrentPage.Url == sub.Url ? "class=active" : "")>
                                                        <a onclick="parent.resizeParent();" href="@sub.Url">@(sub.GetPropertyValue("hoofdstukMenuTitel") != "" ? sub.GetPropertyValue("hoofdstukMenuTitel") : sub.GetPropertyValue("hoofdstukTitel"))</a>
                                                    </li>
                                                }
                                            </ul>
                                            }
                                        }
                                    }
                                }
                                }
                            </ul>
                        </div>
                    </div>
    

    Everything is displaying correctly till I try to navigate to the page, it removes the navigation bar. As far as I am aware the bottom bit (starting at ChildisActive) should make it so the navigation bar stays.

    Nav

    Empty Nav

  • Jonathan Richards 288 posts 1742 karma points MVP
    Nov 07, 2017 @ 11:49
    Jonathan Richards
    100

    Hey

    @foreach(var item in Model.Content.Descendants("menu")){
    

    Looks for any descendants of the current page of alias 'menu', I suspect you want to do your searches from the website node.

    @foreach(var item in Model.Content.Ancestor(1).Descendants("menu")){;
    

    Cheers

  • Mike Dorst 53 posts 215 karma points
    Nov 07, 2017 @ 11:54
    Mike Dorst
    0

    Cheers! Any way I can create a dropdown for a structure like this:

    enter image description here

    Help item 3 should be a dropdown in the menu.

Please Sign in or register to post replies

Write your reply to:

Draft