Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all child items under either Sitecore template A or template B

Is there a way to target all child pages under two templates? As in, if template name is "A" or if template name is "B", get the children?

This is what I have, and it only targets one template right now but I want to add some sort of or to it so I can get the child items of another:

    Item ContentGroup = CurrentItem.Axes.SelectSingleItem(@"child::*[@@templatename='Section Page']/*[@@templatename='Sub Page Top Level']");

I went to get all child items for templates with the name "Sub Page Top Level" OR "Sub Page Top Level Custom." Is there a way to do this without too much trouble?

like image 568
Dejsa Cocan Avatar asked Jan 08 '23 19:01

Dejsa Cocan


2 Answers

You can use logical operator like or:

/*[@@templatename='Sub Page Top Level' or @@templatename='Sub Page Top Level Custom']
like image 181
Marek Musielak Avatar answered Jan 13 '23 19:01

Marek Musielak


If you are using Linq you can use :

homeItem.Axes.GetDescendants().Where(x =>(x.TemplateID.ToString().Equals(yourId1) || x.TemplateID.ToString().Equals(yourId2));

You can also evaluate your sitecore queryes using Sitecore XPath Builder: To get all items under home item based on 2 templates use:

/sitecore/content/home//*[@@templateid='{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}' or @@templateid='{075AB719-9D9C-4ED0-9100-545E87D830A0}' ]

I suggest you to use templateid not templatename. Few years ago I made some tests and is much faster queries using templateid

like image 45
Vlad Iobagiu Avatar answered Jan 13 '23 20:01

Vlad Iobagiu