TemplateBeginRepeat的顺序相反

use*_*001 6 tridion tridion-2011

我需要TemplateBeginRepeat在需要输出自定义标签的位置创建2个循环

<!-- TemplateBeginRepeat name="customtag" -->
    ${RenderComponentPresentation(Field, rendercustomtagstarttemplate)}
<!-- TemplateEndRepeat -->
Run Code Online (Sandbox Code Playgroud)

输出一些HTML

<!-- TemplateBeginRepeat name="customtag" -->
    ${RenderComponentPresentation(Field, rendercustomtagclosetemplate)}
<!-- TemplateEndRepeat -->
Run Code Online (Sandbox Code Playgroud)

由于第二个循环关闭由第一个循环呈现的自定义标记,因此第二个循环应以相反的顺序运行.(因为标签需要以相反的顺序关闭).如何使用TemplateBeginRepeat以相反的顺序运行第二个循环?

Fra*_*len 6

没有内置的方法以相反的顺序循环重复的项目.


如果您customtag是包中的数组项(通常是组件或组件演示文稿的数组),则可以按顺序将列表推送到包含相同项的包中,然后循环该项.

<!-- TemplateBeginRepeat name="customtag_reversed" -->
Run Code Online (Sandbox Code Playgroud)

如果您customtag是一个字段,这将无法工作,因为您无法将字段推入包中.在这种情况下,我建议创建一个自定义函数,以正确的顺序输出您的自定义标签,例如:

@@RenderCustomTags('customtag', 'Order.Reverse')@@
Run Code Online (Sandbox Code Playgroud)

更新

如果customtag组件链接字段,最好将这些链接的组件作为组件数组项添加到包中.Nuno在SDL Tridion World上提供了TBB的链接,但这是最关键的片段:

//  Tridion.ContentManager.Templating.ComponentPresentation
var list = new List<ComponentPresentation>(); 

list.Add(new ComponentPresentation(Component.Id, ComponentTemplate.Id));
// you'll want to do a loop of these for every linked Component

var item = package.CreateStringItem(ContentType.ComponentArray,
                                    ComponentPresentationList.ToXml(list));
package.PushItem("customtag_Components", item);
Run Code Online (Sandbox Code Playgroud)

您需要为每个链接的组件执行这些循环:

list.Add(new ComponentPresentation(Component.Id, ComponentTemplate.Id));
Run Code Online (Sandbox Code Playgroud)

而不是在C#代码中对组件模板ID进行硬编码,您也可以考虑在C#中将其保留为空,并将其保留RenderComponentPresentation在DWT中的调用中,就像您已经做的那样.


Dom*_*nin 5

这里的问题似乎是Dreamweaver语法仅适用于最简单的编程任务.Frank和Nuno已经证明将一些逻辑移到C#模板会有所改进,但是你也应该考虑将这个输出的生成完全转移到C#模板.换句话说,一旦你需要使用除DWT之外的其他东西,你的问题定义就会改变,因为现在描述的问题是以DWT为中心的.

只存在反向循环的需要,因为您希望以正确的顺序关闭构造.在像C#这样的语言中,你可以通过使用嵌套(甚至是递归)函数调用来实现这个结果,或者(或许更有可能)通过将结束输出推送到堆栈来实现.