Skip to content

Instantly share code, notes, and snippets.

@techphoria414
Last active December 27, 2015 15:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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)
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