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.
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.
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
not tested but can't you do something like:
@Model.AncestorOrSelf("root") .repository.First()
or
@Model.AncestorOrSelf("root") .repository[1]
@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)
How about this, it will get you the current nodes siblings.
@alex it's not the siblings I'm after, more like the nephews and nieces (without knowing from which uncle or aunt exactly) :)
is working on a reply...