Reputation: 59
I have three document types and its corresponding templates. My tree is as shown below.
1. Video List
2. Video Item
3. Item Details
The Video List page list all items in the Video Item template. Item Details is the child node of Video Item template. I want all nodes in the Video Item from the Item Details page.
i have tried the below code. But it is showing as Xpath need some assembly reference.
Model.Content.XPath("//*[@isDoc and @level = 1]");
Please help
Upvotes: 0
Views: 2632
Reputation: 789
This one is not hard to do. Use @Ancestor
and then @Children
in a @foreach
loop. Read more about traversing with Umbraco on the Umbraco Page.
Assuming we're on the Item Details template (or page, whatever you feel like calling it) and you need to list all your parents and your parents' siblings (if I understand correctly). So you go to the 'grandparent' and you ask for the children:
@foreach (var item in Model.Content.Ancestor("VideoList").Children)
{
//do whatever you feel like in the collection.
//This foreach loop will list you all the Video Item nodes.
}
P.S. I assumed that VideoList is the docTypeAlias that your Video List page has.
Upvotes: 1
Reputation: 59
i got one solution. Here is my code:
var parentClass = Umbraco.TypedContent(Model.Content.Id).Parent.Parent.Children.Where(x => x.DocumentTypeAlias == "videoItem" && x.IsVisible());
But is this a right way to get parent nodes?
Upvotes: 0