When you do Parent.Children.Children on for example Subnode 1, it will look at the parent (Node 2) and find the Children (Subnode 1 and 2) but then there's a problem: .Children expects to get the children from a single node.. and you have 2 of them here!
So what you can do is a little recursion (I am assuming that this is your exact tree, so no nodes higher than Node 1 - 3. Also assuming you only want to go to level 2, so if Subnodes have children, then you don't want to show them. Adjust "Level <= 2" if you DO want to go deeper):
One addition: if your tree does have a parent node above Node 1 - 3, then change Model.AncestorOfSelf() to Model.AncestorOrSelf(1) (meaning: go to level 1). Also change the level to 3 then, as everything will be one level lower..
I think half of your text has been eaten. Can you show me what the expected output should be and on which pages should that appear? Not sure I understand.
So what you really want is go from 2.1 to 2.2 and show all of 2.2's children. There's a nifty little method called .Next() that can move you easily from 2.1 to 2.2 (as it's the Next node):
I needed a for each inside a for each...But instead of the .Children.Skip(1) I used Parent.[nodeTypeAlias] because the nodetype of 2.1 is different from 2.2 etc.
Yay, glad to hear, could you show an example of Parent.[nodeTypeAlias]? Not sure I am familiar with that technique.. Might benefit others in the future as well! :-)
How can I get all the child nodes from the nodes on the same level??
I've something like this:
- Node 1
- Node 2
- Subnode 1
- Subndoe 2
- Node 3
- Subnode 1
- Subnode 2
Now I want alle these subnodes when I'm at the Node 1 page. But something like Model.Parent.Children.Children doesn't work!
Please help!
Thanx!
When you do Parent.Children.Children on for example Subnode 1, it will look at the parent (Node 2) and find the Children (Subnode 1 and 2) but then there's a problem: .Children expects to get the children from a single node.. and you have 2 of them here!
So what you can do is a little recursion (I am assuming that this is your exact tree, so no nodes higher than Node 1 - 3. Also assuming you only want to go to level 2, so if Subnodes have children, then you don't want to show them. Adjust "Level <= 2" if you DO want to go deeper):
Sorry, the indentation is a bit weird..
One addition: if your tree does have a parent node above Node 1 - 3, then change Model.AncestorOfSelf() to Model.AncestorOrSelf(1) (meaning: go to level 1). Also change the level to 3 then, as everything will be one level lower..
My node tree looks like this:
- Topnode (level 1)
- Node 1
- Node 2
- Subnode 2.1
- Subnode 2.2
- Subnode 2.2.1
- Subnode 2.2.2
- Subnode 2.2.3
- Subnode 2.3
- Subnode 2.3.1
- Subnode 2.3.2
- Subnode 2.4
- Subnode 2.4.1
- Subnode 2.4.2
- Subnode 2.4.3
- Node 3
- Node 4
The Subnode 2.1 page must be an overview of the children of nodes Subnode 2.2, Subnode 2.3, Subnode 2.4.
When I do it like you told (with AncestorOrSelf(2) and "Visible && Level
What's wrong?
I think half of your text has been eaten. Can you show me what the expected output should be and on which pages should that appear? Not sure I understand.
There's something wrong with the white spaces...but from "Subnode 2.1" I would have the following output:
And this should appear on ALL pages or just from Node 2 and for all subnodes?
No, this should only appear when I'm at the page "Subnode 2.1".
Aaah, okay, that should be easy! :-)
So what you really want is go from 2.1 to 2.2 and show all of 2.2's children. There's a nifty little method called .Next() that can move you easily from 2.1 to 2.2 (as it's the Next node):
Yes, but also the childs of 2.3 and 2.4...and if there came more, also the childs from 2.5, 2.6 and so on...
Hmm, I don't really get it, so ONLY on 2.1 you want the subpages of 2.2, 2.3, etc?
So basically you want the subnodes of every 2.x item, except for 2.1. Then you can just Skip the first item:
@foreach (dynamic node in Model.Parent.Children.Skip(1)) {
foreach (var item in node.Children) {
}
}
Or, if you want to also show the title of the 2.x items (for example):
edit: added missing .Children
Yes indeed! I already got an error :-)
I needed a for each inside a for each...But instead of the .Children.Skip(1) I used Parent.[nodeTypeAlias] because the nodetype of 2.1 is different from 2.2 etc.
Most important: it works!!
Thanx!!
Yay, glad to hear, could you show an example of Parent.[nodeTypeAlias]? Not sure I am familiar with that technique.. Might benefit others in the future as well! :-)
is working on a reply...