Copied to clipboard

Flag this post as spam?

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


  • chris vdP 13 posts 35 karma points
    Oct 04, 2011 @ 22:46
    chris vdP
    0

    Side Nav of Content Type Page

    I'm struggling a little with how to create a side nav that only displays a specific content type. You can see my latest attempt below. The problem is that on this line var items node.Descendants("Page").Items.Where(=i.Visible)I need children, not descendants, which I could get with a 1 passed in, but I also want to use "Page" so I am not sure how to get both.

     

    @using System.Linq
    @using System.Xml.Linq
    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @helper traverse(DynamicNode node){
    <ul class='sideNav'>
    @{
        var items node.Descendants("Page").Items.Where(=i.Visible);
        foreach (DynamicNode item in items{
            var mylevel "";        
            if(@Model.Id == item.Id)
            {                   
                mylevel ="class=selected";
            }  
            <li @mylevel>
                <href="@item.Url" >@item.Name</a>
                @{
                    if(item.Id == @Model.Id)
                    {    
                        @traverse(item)
                    }
                    else{
                        foreach (var child in item.ChildrenAsList){
                            if(child.Id == @Model.Id){@traverse(item);break;}                                                         
                        }
                   }
                 }
              </li>
        }
    }
    </ul>
    }
    <h3><href='@Model.AncestorOrSelf(2).Url'>@Model.AncestorOrSelf(2).Name</a><span id='whiteBox'></span></h3>
    @traverse(@Model.AncestorOrSelf(2))


     

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Oct 04, 2011 @ 22:49
    Sebastiaan Janssen
    0

    Try: 

    @helper traverse (dynamic node) {
      var items = node.Children.Where("Visible").Where("NodeTypeAlias = \"Page\"") {
        //etc.
      }

    And later instead of ChildrenAsList, use Children 

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Oct 04, 2011 @ 22:52
    Sebastiaan Janssen
    0

    Sorry, updated above post, I forgot you wanted the children instead of descendants.

  • chris vdP 13 posts 35 karma points
    Oct 04, 2011 @ 22:54
    chris vdP
    0

    Awesome, thank you very much!

     

     

Please Sign in or register to post replies

Write your reply to:

Draft