Is there a way to pass a variable through when calling RenderComponentPresentation? [duplicate]

对着背影说爱祢 提交于 2019-12-06 20:56:42

问题


Possible Duplicate:
Variable setting in Dreamweaver template in SDL Tridion

We use RenderComponentPresentation (on Tridion 2009) to render internal and external links so that the code base is in only one Dreamweaver template. It would be helpful if we could pass through an optional CSS Class to use when rendering the link.

Any ideas how this could be done?


回答1:


It is possible to set a value in the RenderContext and then retrieve it in the second Dreamweaver template.

Before calling RenderComponentPresentation set a render context value as follows:

@@SetRenderContextVariable("CSSClass","red")@@  

You will need to have a C# Fragment or TBB to get the variables out of the render context and add them to the package in the second Dreamweaver template. An example would be:

var renderContext = engine.PublishingContext.RenderContext;
foreach (string key in renderContext.ContextVariables.Keys)
{
    var value = renderContext.ContextVariables[key] as string;
    var item = package.CreateStringItem(ContentType.Text, value);
    package.PushItem("RenderContextVariable."+key, item);
}

You should then be able to access the variables within the package using the standard Dreamweaver notation

@@RenderContextVariable.CSSClass@@

Hope this helps!



来源:https://stackoverflow.com/questions/10431725/is-there-a-way-to-pass-a-variable-through-when-calling-rendercomponentpresentati

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!