Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();
like image 414
David Avatar asked Nov 22 '12 14:11

David


1 Answers

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();
like image 153
Martijn van der Put Avatar answered Nov 11 '22 16:11

Martijn van der Put