vishal vazkar
vishal vazkar

Reputation: 338

How to get a child of child ? Umbraco CMS

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).

Example Screenshot

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

Answers (2)

Jan Bluemink
Jan Bluemink

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

vishal vazkar
vishal vazkar

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

Related Questions