本文整理汇总了C#中Engine.RenderComponentPresentation方法的典型用法代码示例。如果您正苦于以下问题:C# Engine.RenderComponentPresentation方法的具体用法?C# Engine.RenderComponentPresentation怎么用?C# Engine.RenderComponentPresentation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Engine
的用法示例。
在下文中一共展示了Engine.RenderComponentPresentation方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildComponentPresentation
public static Dynamic.ComponentPresentation BuildComponentPresentation(TCM.ComponentPresentation tcmComponentPresentation, Engine engine, int linkLevels, bool resolveWidthAndHeight, BuildManager manager)
{
Dynamic.ComponentPresentation cp = new Dynamic.ComponentPresentation();
if (tcmComponentPresentation.ComponentTemplate.IsRepositoryPublishable)
{
// call render but ignore the output - render ensures componentlinking will be setup as normal.
// don't bother with page flags because the end result is dynamically published so it needs to run with DCP settings
engine.RenderComponentPresentation(tcmComponentPresentation.Component.Id, tcmComponentPresentation.ComponentTemplate.Id);
// ignore the rendered CP, because it is already available in the broker
// instead, we will render a very simple version without any links
cp.Component = manager.BuildComponent(tcmComponentPresentation.Component, 0, false,false); // linkLevels = 0 means: only summarize the component
cp.IsDynamic = true;
}
else
{
// render the component presentation using its own CT
// but first, set a parameter in the context so that the CT will know it is beng called
// from a DynamicDelivery page template
if (engine.PublishingContext.RenderContext != null && !engine.PublishingContext.RenderContext.ContextVariables.Contains(BasePageTemplate.VariableNameCalledFromDynamicDelivery))
{
engine.PublishingContext.RenderContext.ContextVariables.Add(BasePageTemplate.VariableNameCalledFromDynamicDelivery, BasePageTemplate.VariableValueCalledFromDynamicDelivery);
}
string renderedContent = engine.RenderComponentPresentation(tcmComponentPresentation.Component.Id, tcmComponentPresentation.ComponentTemplate.Id);
engine.PublishingContext.RenderContext.ContextVariables.Remove(BasePageTemplate.VariableNameCalledFromDynamicDelivery);
renderedContent = TridionUtils.StripTcdlTags(renderedContent);
cp.IsDynamic = false;
TextReader tr = new StringReader(renderedContent);
if (serializer == null)
{
serializer = new ComponentSerializer();
//serializer = new XmlSerializerFactory().CreateSerializer(typeof(Dynamic.Component));
}
try
{
cp.Component = (Dynamic.Component)serializer.Deserialize(tr);
}
catch (Exception e)
{
TemplatingLogger.GetLogger(typeof(ComponentPresentationBuilder)).Error("exception while deserializing into CP: " + e.Message);
// the component presentation could not be deserialized, this probably not a Dynamic Delivery template
// just store the output as 'RenderedContent' on the CP
cp.RenderedContent = renderedContent;
// because the CT was not a DD4T CT, we will generate the DD4T XML code here
cp.Component = manager.BuildComponent(tcmComponentPresentation.Component);
}
}
cp.ComponentTemplate = manager.BuildComponentTemplate(tcmComponentPresentation.ComponentTemplate);
return cp;
}
示例2: BuildComponentPresentation
public static Dynamic.ComponentPresentation BuildComponentPresentation(TCM.ComponentPresentation tcmComponentPresentation, Engine engine, BuildManager manager)
{
TemplatingLogger logger = TemplatingLogger.GetLogger(typeof(ComponentPresentationBuilder));
Dynamic.ComponentPresentation cp = new Dynamic.ComponentPresentation();
logger.Debug(string.Format(">BuildCP {0} ({1})", tcmComponentPresentation.ComponentTemplate.Title, tcmComponentPresentation.ComponentTemplate.IsRepositoryPublishable));
if (tcmComponentPresentation.ComponentTemplate.IsRepositoryPublishable)
{
// call render but ignore the output - render ensures componentlinking will be setup as normal.
// don't bother with page flags because the end result is dynamically published so it needs to run with DCP settings
engine.RenderComponentPresentation(tcmComponentPresentation.Component.Id, tcmComponentPresentation.ComponentTemplate.Id);
// ignore the rendered CP, because it is already available in the broker
// instead, we will render a very simple version without any links
cp.Component = manager.BuildComponent(tcmComponentPresentation.Component, 0); // linkLevel = 0 means: only summarize the component
cp.IsDynamic = true;
}
else
{
// render the component presentation using its own CT
// but first, set a parameter in the context so that the CT will know it is beng called
// from a DynamicDelivery page template
if (engine.PublishingContext.RenderContext != null && !engine.PublishingContext.RenderContext.ContextVariables.Contains(BasePageTemplate.VariableNameCalledFromDynamicDelivery))
{
engine.PublishingContext.RenderContext.ContextVariables.Add(BasePageTemplate.VariableNameCalledFromDynamicDelivery, BasePageTemplate.VariableValueCalledFromDynamicDelivery);
}
string renderedContent = engine.RenderComponentPresentation(tcmComponentPresentation.Component.Id, tcmComponentPresentation.ComponentTemplate.Id);
renderedContent = TridionUtils.StripTcdlTags(renderedContent);
try
{
// we cannot be sure the component template uses the same serializer service as the page template
// so we will call a factory which can detect the correct service based on the content
ISerializerService serializerService = SerializerServiceFactory.FindSerializerServiceForContent(renderedContent);
cp = serializerService.Deserialize<Dynamic.ComponentPresentation>(renderedContent);
}
catch (Exception e)
{
log.Error("exception while deserializing into CP", e);
// the component presentation could not be deserialized, this probably not a Dynamic Delivery template
// just store the output as 'RenderedContent' on the CP
cp.RenderedContent = renderedContent;
// because the CT was not a DD4T CT, we will generate the DD4T XML code here
cp.Component = manager.BuildComponent(tcmComponentPresentation.Component);
}
cp.IsDynamic = false;
}
cp.ComponentTemplate = manager.BuildComponentTemplate(tcmComponentPresentation.ComponentTemplate);
return cp;
}
示例3: Transform
public void Transform(Engine engine, Package package)
{
Page page = (Page)engine.GetObject(package.GetByName(Package.PageName));
StringBuilder output = new StringBuilder();
foreach (CP cp in page.ComponentPresentations)
{
output.Append(engine.RenderComponentPresentation(cp.Component.Id, cp.ComponentTemplate.Id));
}
package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Html, output.ToString()));
}
示例4: Transform
public override void Transform(Engine engine, Package package)
{
Initialize(engine, package);
Page page = GetPage();
StringBuilder output = new StringBuilder();
if (page != null)
{
foreach (ComponentPresentation cp in page.ComponentPresentations)
{
output.AppendLine(RemoveTcdl(engine.RenderComponentPresentation(cp.Component.Id, cp.ComponentTemplate.Id)));
}
}
package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Text, output.ToString()));
}
示例5: Transform
public void Transform(Engine engine, Package package)
{
_engine = engine;
_package = package;
_log = TemplatingLogger.GetLogger(GetType());
TemplateType templateType;
if (package.GetByName(Package.ComponentName) != null)
templateType = TemplateType.Component;
else
templateType = TemplateType.Page;
Item output = null;
if (templateType == TemplateType.Page)
{
Page page = (Page)engine.GetObject(package.GetByName(Package.PageName));
page.Load(LoadFlags.KeywordXlinks);
output = package.CreateXmlDocumentItem(ContentType.Xml, page.ToXml(XmlFormat.R6Native, XmlSections.All).OwnerDocument);
foreach (ComponentPresentation cp in page.ComponentPresentations)
{
engine.RenderComponentPresentation(cp.Component.Id, cp.ComponentTemplate.Id);
}
}
if (templateType == TemplateType.Component)
{
Component component = (Component)engine.GetObject(package.GetByName(Package.ComponentName));
component.Load(LoadFlags.KeywordXlinks);
output = package.CreateXmlDocumentItem(ContentType.Xml, component.ToXml(XmlFormat.R6Native, XmlSections.All).OwnerDocument);
if(component.BinaryContent != null)
{
package.PushItem(package.CreateMultimediaItem(component));
}
}
if (output != null)
package.PushItem(Package.OutputName, output);
}