I'm trying to find all templates that inherit a particular template through code. I have the ID of the base template (Base Web Page
), and I'm iterating through all of the template items in Sitecore looking for items that inherit Base Web Page
.
foreach (var item in templateItems)
{
var baseTemplates = item.Template.BaseTemplates.ToList();
foreach (var baseTemplate in baseTemplates)
{
if (baseTemplate.ID == templateItem.ID)
{
inheritors.Add(item.ID.ToString());
}
}
}
However, item.Template.BaseTemplates
gives me a list of the root level base templates; instead of giving me Base Web Page
, it gives me the templates that Base Web Page
inherits from (Advanced
, Appearance
, Help
, etc)
Therefore I don't know if the item is actually inheriting Base Web Page
or not.
Is there a method to get directly inherited templates? How can I find all templates that inherit Base Web Page
?