Copied to clipboard

Flag this post as spam?

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


  • Carlos 338 posts 472 karma points
    Dec 13, 2013 @ 20:10
    Carlos
    0

    Navigation with sub navigation, only show current node's subnav or current Nodes parent subnav

    I have my navigation buile and have a question about navigation with subnav and showing only the current nodes subnav IF the current node is selected AND if the current node is a subpage of the node with the subnav.  Currently my navigation is showing ALL subnav if I am on a node with sub navigation in it. I only need to show the current nodes subnav or if it current node is a child of the main nav node with the subnav then I need to also show its siblings nav.  

    This is what I have so far. There is a small thing I am missing and I can't figure out what it is.

    <nav id="minisiteMenuBar">
    <ul>
        @{var homeNode = @Model.AncestorOrSelf("MinisiteHomepage");}
        <li><a href="@homeNode.Url" class="@Library.If(homeNode.Id == Model.Id, "selected", "")">Home</a></li>
            @foreach (var page in homeNode.Children.Where("Visible"))
            {
                <li>
                    <a href="@page.Url" class="@Library.If(page.Id == Model.Id, "selected", "")">@page.Name</a>
    
                    @if(@Model.NodeTypeAlias == "MinisitePage" && @Model.Children.Where("Visible").Count() > 0){
    
                        if(@page.Children.Where("Visible").Count() > 0)
                        {
                        <ul>
                            @foreach(var childPage in page.Children.Where("Visible && NodeTypeAlias == \"MinisitePage\""))
                            {   
                                <li><a href="@childPage.Url" class="@Library.If(childPage.Id == Model.Id, "selected", "")">@childPage.Name</a></li>
                            }
                        </ul> 
                        }
                    }
                else if(@Model.Parent.NodeTypeAlias == "MinisitePage"){
                        <ul>
                        @foreach(var childPage in page.Children.Where("Visible && NodeTypeAlias == \"MinisitePage\""))
                        {   
                            <li><a href="@childPage.Url" class="@Library.If(childPage.Id == Model.Id, "selected", "")">@childPage.Name</a></li>
                        }
                        </ul>
                        }
                        else{}
    
                </li> 
            }
    
    
    </ul>
    
    </nav>
    }
  • Carlos 338 posts 472 karma points
    Dec 16, 2013 @ 19:56
    Carlos
    0

    I found my issue.

    For my else if statement it should look like this

    else if(page.Id == Model.Parent.Id){ <ul> @foreach(var childPage in @Model.Parent.Children.Where("Visible && NodeTypeAlias == \"MinisitePage\"")){ <li><a href="@childPage.Url" class="@Library.If(childPage.Id == Model.Id, "subSelected", "")"> @childPage.Name</a></li> } </ul> }
  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Dec 16, 2013 @ 20:24
    Dennis Aaen
    0

    Hi Carlos,

    Try this one instead.

    <nav id="minisiteMenuBar">
    <ul>
        @{var homeNode = Model.AncestorOrSelf("MinisiteHomepage");}
       
    <li><a href="@homeNode.Url"class="@Library.If(homeNode.Id == Model.Id, "selected", "")">Home</a></li>
            @foreach (var page in homeNode.Children.Where("Visible"))
            {
               
    <li>
                   
    <a href="@page.Url"class="@Library.If(page.Id == Model.Id, "selected", "")">@page.Name</a>

                    @if(Model.NodeTypeAlias == "MinisitePage" && Model.Children.Where("Visible").Count() > 0){

                        if(@page.Children.Where("Visible").Count() > 0)
                        {
                       
    <ul>
                            @foreach(var childPage in page.Children.Where("Visible && NodeTypeAlias == \"MinisitePage\""))
                            {  
                               
    <li><a href="@childPage.Url"class="@Library.If(childPage.Id == Model.Id, "selected", "")">@childPage.Name</a></li>
                            }
                       
    </ul>
                        }
                    }
                else if(Model.Parent.NodeTypeAlias == "MinisitePage"){
                       
    <ul>
                        @foreach(var childPage in page.Children.Where("Visible && NodeTypeAlias == \"MinisitePage\""))
                        {  
                           
    <li><a href="@childPage.Url"class="@Library.If(childPage.Id == Model.Id, "selected", "")">@childPage.Name</a></li>
                        }
                       
    </ul>
                        }
                        else{}

               
    </li>
            }


    </ul>

    </nav>
    }

    Hope this helps,

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft