Copied to clipboard

Flag this post as spam?

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


  • Jens Kvist 10 posts 30 karma points
    Apr 09, 2014 @ 14:44
    Jens Kvist
    0

    Getting specific childpages to show in navigation

    Hello everyone.

    I am wondering how I could show only a few pages from my content tree, in my navigation.

    This is what my content tree looks like

    ------------------------------------------------------------------------

    Content

    Home

    Website

    AdWords

    SEO

    References

    Services

    Contact

    --------------------------------------------------------

    What I wanna do, is hiding the "References" and "Services" pages in my navigation. How can I do that? Here is my script so far:

    @{

        var root = Model.AncestorOrSelf(1);

    var homeActive = "";

     

    if(root.Id == Model.Id){

            homeActive = "active";

        }

    }

     

    <ul class="nav navbar-nav navbar-right">

    <li class="@homeActive">

    <a href="@root.Url">@root.Name</a>

    </li>

     

        @foreach (var page in root.Children.Where("Visible"))

        {

    <li class="@page.IsAncestorOrSelf(Model, "active", "")">

    <a href="@page.Url">@page.Name</a>

    </li>

    }

    </ul>

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Apr 09, 2014 @ 15:21
    Alex Skrypnyk
    0

    Hi Jens,

    You can restrict pages filtering by DocType or Name or Id, DocType is preferred way. Are your pages from different docTypes ?

    Thanks, Alex

  • Phillip Turner 98 posts 412 karma points
    Apr 09, 2014 @ 17:09
    Phillip Turner
    0

    Hey Jens You Could add a property to your DocumentType and then in your code to check if that value is true.

    This is what I am doing currently on my base DocumentType that is inherited by all my other main DocumentTypes:

    Added a Property: Hide From Nav : umbracoNaviHide : True/False.

    Then in my razor, I do this:

    <ul class="nav">            
    @foreach (var childPage in Model.AncestorOrSelf(1).Children.Where("Visible"))
    {
    <li><a href="@childPage.Url">@childPage.Name</a></li>
    }
    </ul>
    

    umbracoNaviHide is an Umbraco standard for the hiding of items from navigation.

    Hope this is of some help

    Phillip

  • Jens Kvist 10 posts 30 karma points
    Apr 10, 2014 @ 09:00
    Jens Kvist
    0

    Thank you so much Phillip! I didn't think of that.

Please Sign in or register to post replies

Write your reply to:

Draft