private static bool MustInclude(IComponentTemplate itemToCheck, string[] pattern) { if (pattern.Length == 0) { return(true); // if no template was specified, always render the component presentation (so return true) } if (pattern[0].StartsWith("tcm:")) { return(pattern.Any <string>(item => item.Equals(itemToCheck.Id))); } else { // pattern does not start with tcm:, we will treat it as a (part of a) view IField view; if (itemToCheck.MetadataFields != null && itemToCheck.MetadataFields.TryGetValue("view", out view)) { return(pattern.Any <string>(item => view.Value.ToLower().StartsWith(item.ToLower()))); } else { System.Diagnostics.Trace.TraceError("view for {0} not set", itemToCheck.Title); return(false); } } }
private static bool MustInclude(IComponentTemplate itemToCheck, string[] pattern) { if (pattern.Length == 0) { return true; // if no template was specified, always render the component presentation (so return true) } if (pattern[0].StartsWith("tcm:")) { return pattern.Any<string>(item => item.Equals(itemToCheck.Id)); } else { // pattern does not start with tcm:, we will treat it as a (part of a) view IField view; if (itemToCheck.MetadataFields != null && itemToCheck.MetadataFields.TryGetValue("view", out view)) { return pattern.Any<string>(item => view.Value.ToLower().StartsWith(item.ToLower())); } else { System.Diagnostics.Trace.TraceError("view for {0} not set", itemToCheck.Title); return false; } } }
/// <summary> /// Renders the XPM Markup for a Component Presentation /// </summary> /// <param name="model">Model</param> /// <param name="region">Region</param> /// <returns>XPM Markup</returns> public HtmlString StartXpmEditingZone(IViewModel parentModel = null) { IComponentTemplate overrideComponentTemplate = null; if (parentModel != null) { overrideComponentTemplate = ((IComponentPresentation)parentModel.ModelData).ComponentTemplate; } return(IsSiteEditEnabled(model) ? new HtmlString(XpmMarkupService.RenderXpmMarkupForComponent(((IComponentPresentation)model.ModelData), overrideComponentTemplate)) : MvcHtmlString.Empty); }
private bool MustInclude(IComponentTemplate itemToCheck, string[] pattern) { if (pattern.Length == 0) { return(true); // if no template was specified, always render the component presentation (so return true) } if (pattern[0].StartsWith("tcm:")) { return(pattern.Any <string>(item => item.Equals(itemToCheck.Id))); } else { // pattern does not start with tcm:, we will treat it as a (part of a) view string viewName = GetComponentTemplateView(itemToCheck); return(pattern.Any <string>(item => viewName.ToLower().StartsWith(item.ToLower()))); } }
/// <summary> /// Resolve the viewName of the given ComponentTemplate. /// /// This should be defined in the MetadataFields, if not the ComponentTemplate name will be used and stripped of spaces. /// </summary> /// <param name="componentTemplate">ComponentTemplate to use</param> /// <returns>Resolved viewName</returns> public string GetComponentTemplateView(IComponentTemplate componentTemplate) { string viewName = null; // If MetadataFields are empty or view is not present, fallback to the name of the componentTemplate if (componentTemplate.MetadataFields == null || !componentTemplate.MetadataFields.ContainsKey("view")) viewName = componentTemplate.Title.Replace(" ", ""); else viewName = componentTemplate.MetadataFields["view"].Value; // If for any reason resolving the name fails or returns an empty value, throw an exception if (string.IsNullOrEmpty(viewName)) { throw new ConfigurationException("no viewName could be resolved for component template " + componentTemplate.Id); } return viewName; }
private bool MustInclude(IComponentTemplate itemToCheck, string[] pattern) { if (pattern[0].StartsWith("tcm:")) { return(pattern.Any <string>(item => item.Equals(itemToCheck.Id))); } else { // pattern does not start with tcm:, we will treat it as a (part of a) title IField view; if (itemToCheck.MetadataFields != null && itemToCheck.MetadataFields.TryGetValue("view", out view)) { string viewName = FactoryService.ModelFactory.MapComponentViewName(view.Value); return(pattern.Any <string>(item => item.Equals(viewName))); } else { System.Diagnostics.Trace.TraceError("view for {0} not set", itemToCheck.Title); return(false); } } }
private bool MustInclude(IComponentTemplate itemToCheck, string[] pattern) { if (pattern[0].StartsWith("tcm:")) { return pattern.Any<string>(item => item.Equals(itemToCheck.Id)); } else { // pattern does not start with tcm:, we will treat it as a (part of a) title IField view; if (itemToCheck.MetadataFields != null && itemToCheck.MetadataFields.TryGetValue("view", out view)) { string viewName = FactoryService.ModelFactory.MapComponentViewName(view.Value); return pattern.Any<string>(item => item.Equals(viewName)); } else { System.Diagnostics.Trace.TraceError("view for {0} not set", itemToCheck.Title); return false; } } }
/// <summary> /// Resolve the viewName of the given ComponentTemplate. /// /// This should be defined in the MetadataFields, if not the ComponentTemplate name will be used and stripped of spaces. /// </summary> /// <param name="componentTemplate">ComponentTemplate to use</param> /// <returns>Resolved viewName</returns> public string GetComponentTemplateView(IComponentTemplate componentTemplate) { string viewName = null; // If MetadataFields are empty or view is not present, fallback to the name of the componentTemplate if (componentTemplate.MetadataFields == null || !componentTemplate.MetadataFields.ContainsKey("view")) { viewName = componentTemplate.Title.Replace(" ", ""); } else { viewName = componentTemplate.MetadataFields["view"].Value; } // If for any reason resolving the name fails or returns an empty value, throw an exception if (string.IsNullOrEmpty(viewName)) { throw new ConfigurationException("no viewName could be resolved for component template " + componentTemplate.Id); } return(viewName); }
public string RenderXpmMarkupForComponent(IComponentPresentation cp, IComponentTemplate overrideComponentTemplate = null) { return(XPMTags.GenerateSiteEditComponentTag(cp, overrideComponentTemplate)); }
/// <summary> /// Generates a SiteEdit tag for a componentpresentation. It also needs to know which region it's in (for component /// swapping) and the order of the page (for a true unique ID). /// </summary> /// <param name="cp">The componentpresentation to mark.</param> /// <returns>string representing the JSON SiteEdit tag.</returns> public static string GenerateSiteEditComponentTag(IComponentPresentation cp, IComponentTemplate overrideComponentTemplate = null) { // is query based tells us if the dcp was the result of a broker query and the component presentation is not embedded on the page string isQueryBased = cp.IsDynamic ? ", \"IsQueryBased\" : true" : string.Empty; // bug 48: allow developer to override the component template ID and modified date/time if (cp.ComponentTemplate == null && overrideComponentTemplate == null) { return(string.Empty); } string ctId = overrideComponentTemplate == null ? cp.ComponentTemplate.Id : overrideComponentTemplate.Id; DateTime ctModifiedDate = overrideComponentTemplate == null ? cp.ComponentTemplate.RevisionDate : overrideComponentTemplate.RevisionDate; return(string.Format(ComponentSeFormat, cp.Component.Id, string.Format("{0:s}", cp.Component.RevisionDate), ctId, string.Format("{0:s}", ctModifiedDate), cp.IsDynamic.ToString().ToLower(), isQueryBased)); }
public ComponentTemplate(IComponentTemplate template) { this.template = template; this.metadataFields = new FieldSet(template.MetadataFields); }
public ComponentPresentation(IComponent component, IComponentTemplate template) { this.cp = Helper.BuildComponentPresentation(component, template); //Helps get around naming conflicts this.component = new Component(component); this.template = new ComponentTemplate(template); }
private bool MustInclude(IComponentTemplate itemToCheck, string[] pattern) { if (pattern.Length == 0) { return true; // if no template was specified, always render the component presentation (so return true) } if (pattern[0].StartsWith("tcm:")) { return pattern.Any<string>(item => item.Equals(itemToCheck.Id)); } else { // pattern does not start with tcm:, we will treat it as a (part of a) view string viewName = GetComponentTemplateView(itemToCheck); return pattern.Any<string>(item => viewName.ToLower().StartsWith(item.ToLower())); } }