Copied to clipboard

Flag this post as spam?

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


  • Vincent Baaij 95 posts 344 karma points c-trib
    Mar 22, 2011 @ 11:41
    Vincent Baaij
    0

    Navigate up the tree, then list children of specific node

    I have the following tree structure in my site:

     

    Root (alias root)

    Repository (alias repository)

    item 1

    item 2

    item 3

    Navigation

    News

    Events

     

    Now in the template of the news item, I want to display (a selection of) the items in the repository. How do I go about this with Razor?

    I know I can use @Model.AncestorOrSelf("root") to get to the root item, but how do I go down to the repository next to use that node in a foreach loop?

    There will always be only one repository. If I use @Model.AncestorOrSelf("root") .repository, the type returned is a DynamicNodeList so that cannot be used in the foreach loop.

     

    Confusing stuff. Help appreciated.

  • Vincent Baaij 95 posts 344 karma points c-trib
    Mar 22, 2011 @ 11:48
    Vincent Baaij
    0

    Can't seem tot edit the past. Tree struce did not get posted right.

    Explanation:  

    Repository and Navigation are children of Root

    Item1, Item 2 and Item 3 are children of Repository

    News and Events are children of Navigation

  • Yannick Smits 321 posts 718 karma points
    Mar 22, 2011 @ 13:32
    Yannick Smits
    0

    not tested but can't you do something like:

    @Model.AncestorOrSelf("root") .repository.First()

    or

    @Model.AncestorOrSelf("root") .repository[1]

  • Vincent Baaij 95 posts 344 karma points c-trib
    Mar 22, 2011 @ 14:02
    Vincent Baaij
    0

    @Yannick

    First() works!

    [] gives error: Cannot apply indexing with [] to an expression of type 'umbraco.MacroEngines.DynamicNodeList'

     

    By looking at the source I found you can also use Down(nodeTypeAlias)

  • Alex 78 posts 136 karma points
    Mar 22, 2011 @ 14:03
    Alex
    0

    How about this, it will get you the current nodes siblings.

     

    @foreach(dynamic child in @Model.Parent.Children)
    {
      @child.Name
    }
  • Vincent Baaij 95 posts 344 karma points c-trib
    Mar 22, 2011 @ 14:11
    Vincent Baaij
    0

    @alex it's not the siblings I'm after, more like the nephews and nieces (without knowing from which uncle or aunt exactly) :)

Please Sign in or register to post replies

Write your reply to:

Draft