/// <summary> /// Gets a list of ComponentPresentationModels from the Component Presentations on the page. Callable from a PageTemplate. /// </summary> /// <param name="templateName">The template's name to filter by.</param> /// <returns>A list of ComponentPresentationModels that match the template's name.</returns> public List <ComponentPresentationModel> GetComponentPresentationsByTemplate(params string[] templateNames) { List <ComponentPresentationModel> componentPresentations = new List <ComponentPresentationModel>(); int i = 0; foreach (ComponentPresentationModel cp in ComponentPresentations) { if (templateNames.Contains(cp.Template.Title)) { var cpm = new ComponentPresentationModel(_engine, (Component)cp.Component.TridionObject, cp.Template.TridionObject); cpm.Index = i++; componentPresentations.Add(cpm); } } if (componentPresentations.Count > 0) { componentPresentations.Last().IsLast = true; } return(componentPresentations); }
/// <summary> /// Create a single component presentation model /// </summary> /// <param name="component"></param> /// <param name="componentTemplate"></param> /// <returns></returns> private ComponentPresentationModel CreateComponentPresentation(Component component, ComponentTemplate componentTemplate) { var linkLevels = componentTemplate.GetLinkLevels(); var presentation = new ComponentPresentationModel { ComponentModel = new ComponentModel { TcmUri = component.Id, Title = component.Title, SchemaName = component.Schema.Title, Content = _mapper.MapItemFields(component.Content, component.Schema, linkLevels), Metadata = _mapper.MapItemFields(component.Metadata, component.MetadataSchema, linkLevels), BinaryUrl = component.BinaryContent != null ? component.PublishBinary(Engine, Package) : null }, TemplateModel = new TemplateModel { TcmUri = component.Id, Title = component.Title, SchemaName = componentTemplate.MetadataSchema != null ? componentTemplate.MetadataSchema.Title : null, Metadata = _mapper.MapItemFields(componentTemplate.Metadata, componentTemplate.MetadataSchema, linkLevels), Priority = componentTemplate.Priority } }; return(presentation); }