Last active
June 6, 2016 18:38
-
-
Save soen/55f3683d0705bd4cf7e48108722b9b9e to your computer and use it in GitHub Desktop.
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 class TemplateItemExtensions | |
{ | |
public static IEnumerable<TemplateFieldItem> GetFieldsOfSelfAndBaseTemplates(this TemplateItem self) | |
{ | |
var templateFieldItems = new Dictionary<ID, TemplateFieldItem>(); | |
GetAllFieldsForTemplate(self, templateFieldItems); | |
return templateFieldItems.Values; | |
} | |
private static void GetAllFieldsForTemplate(TemplateItem template, Dictionary<ID, TemplateFieldItem> templateFieldItems) | |
{ | |
AddFieldsOfTemplate(template, templateFieldItems); | |
if (template.BaseTemplates.Length <= 0) | |
return; | |
foreach (TemplateItem baseTemplate in template.BaseTemplates) | |
GetAllFieldsForTemplate(baseTemplate, templateFieldItems); | |
} | |
private static void AddFieldsOfTemplate(TemplateItem template, Dictionary<ID, TemplateFieldItem> templateFieldItems) | |
{ | |
foreach (TemplateFieldItem x in template.OwnFields) | |
{ | |
if (templateFieldItems.ContainsKey(x.ID) == false) | |
templateFieldItems.Add(x.ID, x); | |
} | |
} | |
} |
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
TemplateItem selectedTemplateItem = Sitecore.Context.ContentDatabase.GetItem(new ID("YourID")); | |
return selectedTemplateItem.GetFieldsOfSelfAndBaseTemplates(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment