Copied to clipboard

Flag this post as spam?

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


  • Sean Dooley 273 posts 490 karma points
    Aug 26, 2011 @ 16:29
    Sean Dooley
    0

    How to find AncestorOrSelf with visible children?

    I am trying to display a subnavigation which displays children of the current page. If there aren't any children, then I would like to display children of the parent.

    Any ideas of what the Razor syntax is?

  • Sean Dooley 273 posts 490 karma points
    Aug 26, 2011 @ 16:38
    Sean Dooley
    0

    Currently using syntax below.

     

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
    var elementClass = String.IsNullOrEmpty(Parameter.ElementClass) ? "" : String.Format(" class=\"{0}\"", Parameter.ElementClass);
    var model = (@Model.Children.Count() > 0) ? @Model : @Model.Parent;
    }
    <ul @Html.Raw(elementClass)>
    @foreach (var item in @model.Children.Where("Visible")) {
    <li><a href="@item.Url">@item.Name</a></li>
    }
    </ul>

    Feel free to make other suggestions. Is there a way of using AncestorsOrSelf()?

     

  • 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