public void Transform(Engine engine, Package package) { // do NOT execute this logic when we are actually publishing! (similair for fast track publishing) if (engine.RenderMode == RenderMode.Publish || (engine.PublishingContext.PublicationTarget != null && !Tcm.TcmUri.IsNullOrUriNull(engine.PublishingContext.PublicationTarget.Id))) { return; } Item outputItem = package.GetByName("Output"); String inputValue = package.GetValue("Output"); if (string.IsNullOrEmpty(inputValue)) { log.Warning("Could not find 'Output' in the package, nothing to preview"); return; } // read staging url from configuration string stagingUrl = TridionConfigurationManager.GetInstance(engine, package).AppSettings["StagingUrl"]; string outputValue = HttpPost(stagingUrl, inputValue); if (string.IsNullOrEmpty(outputValue)) { outputValue = "<h2>There was an error while generating the preview.</h2>"; } // replace the Output item in the package package.Remove(outputItem); package.PushItem("Output", package.CreateStringItem(ContentType.Html, outputValue)); }
/// <summary> /// Adds a value to the Page metadata from the Configuration Component on the Publication Metadata /// </summary> /// <param name="page">Dynamic Delivery Page</param> /// <param name="name">XML field name of value from Configuration Component</param> private void AddConfig(Page page, string name) { TCM.Publication tcmPub = (TCM.Publication) this.GetTcmPage().ContextRepository; string value = TridionConfigurationManager.GetInstance(Engine, tcmPub).AppSettings[name]; Field field = new Field { FieldType = FieldType.Text, Name = name, Values = new List <string>() { value } }; page.MetadataFields.Add(name, field); Logger.Info(string.Format("added field: {0} with value: {1} to Page Metadata", name, value)); }