Yep, i figured i needed to find the top page of type TextPage.
From then i could use the normal functionality of just using .children to get all the children i need for the menu.
Yep, i figured i needed to find the parent, even when i am on the third level.
So i just look for the top parent which is of type TextPage.
And from there i could just use .children.
I don't know if this is the best solution, but so far it works.
Although it is a lot of looking up the tree every page load.
I don't understand why you don't use AncestorsOrSelf(2).
In your example the highest level textpage is on the second level so there's no need to loop through all the parents until you find the highest one right? I would never go with a loop if you know where to go.
With modelsbuilder:
var topLevelTextPage = Model.Content.AncestorsOrSelf<TextPage>().Last();
Without modelsbuilder
var topLevelTextPage = Model.Content.AncestorsOrSelf("textPage").Last();
Persistant menu on textpage
Hi, i have a textpage, which can have it self as children.
In that regard i am trying to figure out a way to have a menu on the page, which persists with the first "textpage", and the children.
Right now it just changes to show the children from the current node.
I am going to be able to have up to three levels in this.
How do i persist the menu from the perspective of the first level, when i navigate down the levels.
You can go up from the current page to the level of choice.
So you can do something like:
}
I thought about that as well, but that would mean it could only be a for example level 2.
What if the first textpage was somehow at level 3 ? then it would miss a step
I'm sorry, I'm not clear with my explanation.
Model.Content.AncestorOrSelf(1)
is the same asModel.Content.Site()
So if you use
Model.Content.AncestorOrSelf(2)
you will start at your first levelI'm sorry for not being clear.
Model.Content.AncestorOrSelf(1)
isModel.Content.Site()
So if you use
Model.Content.AncestorOrSelf(2)
it will start at your First levelDo you have a code example of what you have right now?
Right now i just use Currentpage.Children and then i map those to what i need.
I think i found a solution.
This should go up the tree until it meets something other than a textpage.
Than I misunderstood you. I thought you wanted a menu showing the siblings but this looks more like a breadcrumb
I wanted a persistent menu, which showed children from the point of the first parent that is a textpage.
What you will get with your code is the ancestors of the page you are on.
Yep, i figured i needed to find the top page of type TextPage. From then i could use the normal functionality of just using .children to get all the children i need for the menu.
Yep, i figured i needed to find the parent, even when i am on the third level. So i just look for the top parent which is of type TextPage. And from there i could just use .children.
I don't know if this is the best solution, but so far it works. Although it is a lot of looking up the tree every page load.
I don't understand why you don't use AncestorsOrSelf(2). In your example the highest level textpage is on the second level so there's no need to loop through all the parents until you find the highest one right? I would never go with a loop if you know where to go.
Or is the structure in your first post incorrect?
The structure is correct, but it is also possble that the textpage first starts on the 3rd level or lower.
So it isn't always on the second level.
If that's the case you can use this
Looks a lot more clean, will try it out later.
This works great, alot more clean and easy to understand. Thanks for the help ^^
No problem, glad I could help!
is working on a reply...