Created
October 12, 2015 05:17
-
-
Save Azadehkhojandi/b02a042dc13240342b01 to your computer and use it in GitHub Desktop.
check sitecore implements a template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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