David
David

Reputation: 181

Getting children children in sitecore

I'm trying to list items which have a set template on the parent page in Sitecore. So far I can do it for the children but I also want to include the children's children, i.e. anything under the parent if it has the chosen template it will work, this is my code in the c# file:

lvThing.DataSource = context.Children.Where(x => x.TemplateName == "cool    template").ToList<Item>();
lvThing.DataBind();

Upvotes: 8

Views: 17421

Answers (1)

Martijn van der Put
Martijn van der Put

Reputation: 4092

If you want the items below the children, you can use the item.Axes.GetDescendants() method to get all items below the context item.

Your code then should look like this:

contextItem.Axes.GetDescendants().Where(x => x.TemplateName == "cool    template").ToList();

Upvotes: 14

Related Questions