public static Sitecore.Layouts.RenderingReference[] GetRenderingReferences(this Item item, string deviceName) { LayoutField layoutField = item.Fields["__final renderings"]; if (layoutField == null) { return(null); } Sitecore.Layouts.RenderingReference[] renderings = null; if (item.Database != null) { renderings = layoutField.GetReferences(item.Database.GetDeviceItem(deviceName)); } else { renderings = layoutField.GetReferences(Sitecore.Context.Database.GetDeviceItem(deviceName)); } return(renderings); }
private Sitecore.Layouts.RenderingReference[] GetRenderingReferences(Item item, string deviceName) { LayoutField layoutField = item.Fields["__final renderings"]; if (layoutField == null) { return(null); } RenderingReference[] renderings = layoutField.GetReferences(GetDeviceItem(item.Database, deviceName)); return(renderings); }
/// <summary> /// Get rendering on specified item. /// </summary> /// <param name="item"></param> /// <param name="rendering"></param> /// <returns></returns> private static RenderingReference GetSameRenderingOnItem(Item item, RenderingReference rendering) { LayoutField layoutField = item.Fields[FieldIDs.LayoutField]; if (layoutField == null) { return(null); } RenderingReference[] references = layoutField.GetReferences(Context.Device); if (references == null || references.Length == 0) { return(null); } var renderingOnParentItem = references.FirstOrDefault(r => r.UniqueId == rendering.UniqueId); return(renderingOnParentItem); }
public object ComputeFieldValue(Sitecore.ContentSearch.IIndexable indexable) { var item = (Item)(indexable as SitecoreIndexableItem); if (item == null) { return(null); } // optimization to reduce indexing time // by skipping this logic for items in the Core database if (System.String.Compare( item.Database.Name, "core", System.StringComparison.OrdinalIgnoreCase) == 0) { return(null); } if (item.Paths.IsMediaItem) { //skip media root and folder items if (item.TemplateID != Sitecore.TemplateIDs.MediaFolder && item.ID != Sitecore.ItemIDs.MediaLibraryRoot) { return(null); } } //From Sitecore 8.0 onwards we need to look in Final Renderings for latest content versions LayoutField layoutField = item.Fields["__Final Renderings"]; RenderingReference[] renderings = layoutField.GetReferences(GetDefaultDevice(item.Database)); if (renderings == null) { return(null); } StringBuilder sb = new StringBuilder(); foreach (var renderingReference in renderings) { var datasourceId = renderingReference.Settings.DataSource; //Check if datasource has been set or we get null reference errors if (!string.IsNullOrWhiteSpace(datasourceId)) { var referencedItem = item.Database.GetItem(datasourceId, item.Language); foreach (Field field in referencedItem.Fields) { if (!field.IsStandardTemplateField()) { if (field.Type == "Single-Line Text" || field.Type == "Rich Text") { sb.Append(" ").Append(StripTags(field.Value)); } } } } } return(sb.ToString().Trim()); }