Reputation: 338
I am trying to get a collection of all the child pages which sit in a folder under a page. However, I am struggling with this and CurrentPage.Children returns the folder element (as expected).
I am trying to get all the package (whether domestic or international does not matter, just making it better for the content editors to enter content) and display a few fields from the full package document type on the packages page.
What is the best and neat way in which I can achieve this ?
Thanks, Vishal
Upvotes: 2
Views: 594
Reputation: 3487
One way is get al descedants and filter on the page Level.
@{
foreach (var childchild in CurrentPage.Descendants().Where("Level == " + (CurrentPage.Level+2)))
{
<h2>@childchild.Level @childchild.Name</h2>
}
}
It is also possible to filter on Document Type to ensure you got only the type you want. (the package document type)
Add something like this. .Where("DocumentTypeAlias == \"Package\"")
Combined:
.Where("DocumentTypeAlias == \"Package\" && Level == " + (CurrentPage.Level+2))
Upvotes: 2
Reputation: 338
I got a way around but not the best, so still looking for good answers. I have used the following:
foreach (var item in CurrentPage.Children)
{
foreach (var package in item.Children())
{
<h2>@package.PackageName</h2>
}
}
Upvotes: 1