Copied to clipboard

Flag this post as spam?

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


  • Chris 92 posts 238 karma points
    Jan 07, 2015 @ 10:04
    Chris
    0

    umbracoNaviHide - only works on Root/Home

    Hey,

    I have a problem with the umbracoNaviHide function. I'm using the 7.2.1 version of umbraco and working right now with the starter kit "Fanoe" which was pre installed.

    In the "Fanoe" package the umbracoNaviHide function was used to hide elements in the bottom navigation, which I didn't need so I changed the umbracoNaviHide function so it (with help of this thread: http://our.umbraco.org/forum/using/ui-questions/53448-How-to-remove-About-US-from-top-navigation-but-still-display-Contact-macro-on-homepage ) and it works on the Home/root-page but when I load a child page the topbar-navigation is empty.

    Here is the code of the navigation I am using right know:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{ var home = CurrentPage.Site(); }

    @if (home.Children.Any())
    {
    @* Get the first page in the children *@
    var naviLevel = home.Children.First().Level;

    @* Add in level for a CSS hook *@
    <ul class="level-@naviLevel">
    @* For each child page under the root node, where the property umbracoNaviHide is not True *@
    @foreach (var childPage in CurrentPage.Children.Where("Visible"))
    {
    if (childPage.Children.Any())
    {
    <li class="has-child @(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
    @if(childPage.DocumentTypeAlias == "LandingPage")
    {
    <span>@childPage.Name</span>
    @childPages(childPage.Children)
    } else {
    <a href="@childPage.Url">@childPage.Name</a>
    }
    </li>
    }
    else
    {
    <li class="@(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
    <a href="@childPage.Url">@childPage.Name</a>
    </li>
    }
    }
    </ul>
    }

    @helper childPages(dynamic pages)
    {
    @* Ensure that we have a collection of pages *@
    if (pages.Any())
    {
    @* Get the first page in pages and get the level *@
    var naviLevel = pages.First().Level;

    @* Add in level for a CSS hook *@
    <ul class="sublevel level-@(naviLevel)">
    @foreach (var page in pages)
    {
    <li>
    <a href="@page.Url">@page.Name</a>

    @* if the current page has any children *@
    @if (page.Children.Any())
    {
    @* Call our helper to display the children *@
    @childPages(page.Children)
    }
    </li>
    }
    </ul>
    }
    }

    Would be really gratefull if you can tell me where the error in the code is.

    Thanks for your help,

    Christoph

     

  • Chris 92 posts 238 karma points
    Jan 09, 2015 @ 12:41
    Chris
    100

    Not the perfect solution but it works:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{ var home = CurrentPage.Site(); }

    @if (home.Children.Any())
    {
    @* Get the first page in the children *@
    var naviLevel = home.Children.First().Level;

    @* Add in level for a CSS hook *@
    <ul class="level-@naviLevel">
    @* For each child page under the home node *@
    @foreach (var childPage in home.Children)
    {
    if (!childPage.umbracoNaviHide)
    {
    if (childPage.Children.Any())
    {
    <li class="has-child @(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
    @if(childPage.DocumentTypeAlias == "LandingPage")
    {
    <span>@childPage.Name</span>
    @childPages(childPage.Children)
    } else {
    <a href="@childPage.Url">@childPage.Name</a>
    }
    </li>
    }
    else
    {
    <li class="@(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
    <a href="@childPage.Url">@childPage.Name</a>
    </li>
    }
    }
    }
    </ul>
    }

    @helper childPages(dynamic pages)
    {
    @* Ensure that we have a collection of pages *@
    if (pages.Any())
    {
    @* Get the first page in pages and get the level *@
    var naviLevel = pages.First().Level;

    @* Add in level for a CSS hook *@
    <ul class="sublevel level-@(naviLevel)">
    @foreach (var page in pages)
    {
    if (!page.umbracoNaviHide)
    {
    <li>
    <a href="@page.Url">@page.Name</a>

    @* if the current page has any children *@
    @if (page.Children.Any())
    {
    @* Call our helper to display the children *@
    @childPages(page.Children)
    }
    </li>
    }
    }
    </ul>
    }
    }
Please Sign in or register to post replies

Write your reply to:

Draft