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();
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With