Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sitecore SelectItems on Inherited Template

Tags:

sitecore

I am trying to bind a asp:dropdownlist to a some sitecore items based on a query. With the query I want to return items that inherhit the template 'Site Root'.

When I use:

Sitecore.Context.Database.SelectItems("/sitecore/content/*[@@templatename='Site Root']");

It only returns items that have the template of 'Site Root', not the templates that inherit this template.

How do I get a query to return items that inherit this template?

like image 930
Bevan Avatar asked Mar 27 '11 23:03

Bevan


2 Answers

Here's a query that returns all templates inheriting a specific template. But be careful as it will not perform very well.

/sitecore/templates//*[contains(@__Base template, '<MY TEMPLATE ID>')]

If performance matters, you'd probably be better off using Sitecore ContentSearch to query the templates. There is a __template computed field for that which needs to be activated first though. See Sitecore-7-Enable-Default-Computed-Index-Fields for details.

like image 175
Mark Lowe Avatar answered Nov 07 '22 03:11

Mark Lowe


You can't query on an inherited template

like image 33
Mark Ursino Avatar answered Nov 07 '22 02:11

Mark Ursino