Skip to content

Instantly share code, notes, and snippets.

@Azadehkhojandi
Created October 12, 2015 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Azadehkhojandi/b02a042dc13240342b01 to your computer and use it in GitHub Desktop.
Save Azadehkhojandi/b02a042dc13240342b01 to your computer and use it in GitHub Desktop.
check sitecore implements a template
public static bool Implements(this Item item, params ID[] templateIds)
{
if (templateIds.Length == 0)
{
throw new ArgumentOutOfRangeException("templateIds", "must include at least one template");
}
if (item == null || item.Template == null)
{
return false;
}
var items = new List<TemplateItem> { item.Template };
int index = 0;
// flatten the template tree during search
while (index < items.Count)
{
// check for match
TemplateItem template = items[index];
if (templateIds.Contains(template.ID))
{
return true;
}
// add base templates to the list
items.AddRange(template.BaseTemplates);
// inspect next template
index++;
}
// nothing found
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment