Copied to clipboard

Flag this post as spam?

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


  • Rocoeh 65 posts 86 karma points
    Sep 04, 2012 @ 12:01
    Rocoeh
    0

    Subnav - check item exists

    HI,

    I have a razor generated subnav, I am having issues with pages that have no sub nav items. I suppose I need to check the item exists, but my Razor knowledge is pretty sketchy.

    My Code...

    @using umbraco.MacroEngines
    @inherits DynamicNodeContext
    @{
      
      
     
      var parent = @Model.AncestorOrSelf(1);
      
            <ul class="subnav">
        @foreach (var item in @Model.AncestorOrSelf(2).Children.Where("Visible && umbracoNaviHide!=true"))
            {
                var selected = Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0 ? " class=\"selected\"" : string.Empty;
                <li@Html.Raw(selected)><a href="@item.Url"><span>@item.Name</span></a></li>
            }
            </ul>
      

    }

  • gilad 185 posts 425 karma points
    Sep 04, 2012 @ 12:14
    gilad
    0

    Hi Rocheh.

    Try change the @Model.AncestorOrSelf(2) to parent.

    Another point :  umbracoNaviHide!=true and Visible  is the same.

    so :

     @foreach (var item in parent.Children.Where("Visible"))
    { ..... }

    Hope that help. 

    Cheers

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies