/// <summary> /// Get the content data and render it with the given template to the page. /// </summary> protected void ProcessView(PlaceHolder phOutput, Panel pnlError, Panel pnlMessage) { #region Check if everything has values and return if not if (Template == null) { ShowError(LocalizeString("TemplateConfigurationMissing.Text"), pnlError); return; } if (Template.AttributeSetID.HasValue && DataSource.GetCache(ZoneId.Value, AppId.Value).GetContentType(Template.AttributeSetID.Value) == null) { ShowError("The contents of this module cannot be displayed because it's located in another VDB.", pnlError); return; } if (Template.AttributeSetID.HasValue && !Template.DemoEntityID.HasValue && Items.All(e => !e.EntityID.HasValue)) { var toolbar = IsEditable ? "<ul class='sc-menu' data-toolbar='" + Newtonsoft.Json.JsonConvert.SerializeObject(new { sortOrder = Items.First().SortOrder, useModuleList = true, action = "edit" }) + "'></ul>" : ""; ShowMessage(LocalizeString("NoDemoItem.Text") + " " + toolbar, pnlMessage); return; } #endregion try { //var renderTemplate = Template; string renderedTemplate; var engine = EngineFactory.CreateEngine(Template); var dataSource = (ViewDataSource)Sexy.GetViewDataSource(this.ModuleId, SexyContent.HasEditPermission(this.ModuleConfiguration), Template); engine.Init(Template, Sexy.App, this.ModuleConfiguration, dataSource, Request.QueryString["type"] == "data" ? InstancePurposes.PublishData : InstancePurposes.WebView, Sexy); engine.CustomizeData(); // Output JSON data if type=data in URL if (Request.QueryString["type"] == "data") { if (dataSource.Publish.Enabled) { var publishedStreams = dataSource.Publish.Streams; renderedTemplate = Sexy.GetJsonFromStreams(dataSource, publishedStreams.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); } else { Response.StatusCode = 403; var moduleTitle = new ModuleController().GetModule(ModuleId).ModuleTitle; renderedTemplate = Newtonsoft.Json.JsonConvert.SerializeObject(new { error = "2sxc Content (" + ModuleId + "): " + String.Format(LocalizeString("EnableDataPublishing.Text"), ModuleId, moduleTitle) }); Response.TrySkipIisCustomErrors = true; } Response.ContentType = "application/json"; } else { renderedTemplate = engine.Render(); } // If standalone is specified, output just the template without anything else if (StandAlone) { Response.Clear(); Response.Write(renderedTemplate); Response.Flush(); Response.SuppressContent = true; HttpContext.Current.ApplicationInstance.CompleteRequest(); } else { phOutput.Controls.Add(new LiteralControl(renderedTemplate)); } } // Catch errors; log them catch (Exception Ex) { ShowError(LocalizeString("TemplateError.Text") + ": " + HttpUtility.HtmlEncode(Ex.ToString()), pnlError, LocalizeString("TemplateError.Text"), false); Exceptions.LogException(Ex); } }