Last active
December 27, 2015 15:09
-
-
Save techphoria414/7345228 to your computer and use it in GitHub Desktop.
Sitecore7 computed index field for *really* indexing all base templates (up to the Standard 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Sitecore.ContentSearch; | |
using Sitecore.ContentSearch.ComputedFields; | |
using Sitecore.ContentSearch.Utilities; | |
using Sitecore.Data.Items; | |
namespace MyProject.Search.ComputedFields | |
{ | |
public class AllTemplatesField : IComputedIndexField | |
{ | |
public string FieldName | |
{ | |
get; | |
set; | |
} | |
public string ReturnType | |
{ | |
get; | |
set; | |
} | |
public object ComputeFieldValue(IIndexable indexable) | |
{ | |
var indexItem = indexable as SitecoreIndexableItem; | |
var item = (Sitecore.Data.Items.Item)indexItem.Item; | |
var templates = new List<string>(); | |
this.GetAllTemplates(item.Template, templates); | |
return templates; | |
} | |
public void GetAllTemplates(TemplateItem baseTemplate, List<string> list) | |
{ | |
if (baseTemplate.ID != Sitecore.TemplateIDs.StandardTemplate) | |
{ | |
string str = IdHelper.NormalizeGuid(baseTemplate.ID); | |
list.Add(str); | |
foreach (TemplateItem item in baseTemplate.BaseTemplates) | |
{ | |
this.GetAllTemplates(item, list); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment