Wednesday, January 13, 2016

Get all Items inheriting another template

Working on different templates and Sitecore items, its very common requirement to know

  • how many items are created with a specific template
  • how many template are inheriting a base template or another template

Sitecore provide this feature out of box however you need to write query to fetch the required items.

  1. Open Sitecore IDE (http://localhost/sitecore/shell/default.aspx?xmlcontrol=IDE)
  2. Goto Tools -> XPath Builder
  3. Write XPath Expression:

/sitecore/templates//*[contains(@__Base template,'{1FE1328B-375B-4548-A53E-344FA61ACC90}')]



In result section, it should show all templates which are inheriting base template with ID {1FE1328B-375B-4548-A53E-344FA61ACC90}.

Similarly, query 
/sitecore/content//*[@@templatename='Promotional Page'] should show all pages (under content) created with 'Promotional Page' template.

On top of results, it shows the count of items and time taken to fetch the items.

We can use fast query as well instead of query.

Note: The above queries are example of specific requirement. Query can be modified to get required items according to project need.