private void FindDataPresentationTemplate() { RepositoryLocalObject sourceItem = (RepositoryLocalObject)RenderedItem.ResolvedItem.Item; Publication contextPublication = (Publication)sourceItem.ContextRepository; ComponentTemplatesFilter ctFilter = new ComponentTemplatesFilter(Session) { AllowedOnPage = false, BaseColumns = ListBaseColumns.IdAndTitle }; // TODO: use marker App Data instead of the CTs Title. const string dataPresentationTemplateTitle = "Generate Data Presentation"; _dataPresentationTemplate = contextPublication.GetComponentTemplates(ctFilter).FirstOrDefault(ct => ct.Title == dataPresentationTemplateTitle); if (_dataPresentationTemplate == null) { Logger.Warning($"Component Template '{dataPresentationTemplateTitle}' not found."); _dataPresentationTemplateNotFound = true; } else { Logger.Debug($"Found Data Presentation Template: {_dataPresentationTemplate.FormatIdentifier()}"); } }
private static Dictionary <string, string> GetMvcParameters(ComponentTemplate ct) { // TODO: support Key/Value Pair Schema (multi-valued embedded field) string routeValues = ct.Metadata.GetTextFieldValue("routeValues"); if (string.IsNullOrEmpty(routeValues)) { return(null); } Dictionary <string, string> result = new Dictionary <string, string>(); foreach (string[] keyValuePair in routeValues.Split(',').Select(routeValue => routeValue.Split(':'))) { if (keyValuePair.Length != 2) { throw new DxaException($"Invalid syntax for 'routeValues' field in {ct.FormatIdentifier()}: '{keyValuePair}'"); } result.Add(keyValuePair[0].Trim(), keyValuePair[1].Trim()); } return(result); }
/// <summary> /// Performs the Transform. /// </summary> public override void Transform(Engine engine, Package package) { Logger.Debug("Transform"); Initialize(engine, package); bool includeComponentTemplateData; if (!package.TryGetParameter("includeComponentTemplateData", out includeComponentTemplateData, Logger)) { includeComponentTemplateData = true; // Default } int expandLinkDepth; package.TryGetParameter("expandLinkDepth", out expandLinkDepth, Logger); string[] modelBuilderTypeNames = GetModelBuilderTypeNames(); RenderedItem renderedItem = Engine.PublishingContext.RenderedItem; Component component = GetComponent(); ComponentTemplate ct = GetComponentTemplate(); try { DataModelBuilderSettings settings = new DataModelBuilderSettings { ExpandLinkDepth = expandLinkDepth, GenerateXpmMetadata = IsXpmEnabled || IsPreview }; DataModelBuilderPipeline modelBuilderPipeline = new DataModelBuilderPipeline(renderedItem, settings, modelBuilderTypeNames); EntityModelData entityModel = modelBuilderPipeline.CreateEntityModel(component, ct, includeComponentTemplateData); OutputJson = JsonSerialize(entityModel, IsPreview, DataModelBinder.SerializerSettings); } catch (Exception ex) { throw new DxaException($"An error occurred while rendering {component.FormatIdentifier()} with {ct.FormatIdentifier()}", ex); } }