我需要使用TemplateBeginRepeat
创建2个循环,我需要输出自定义标签
<!-- TemplateBeginRepeat name="customtag" -->
${RenderComponentPresentation(Field, rendercustomtagstarttemplate)}
<!-- TemplateEndRepeat -->
输出一些HTML
<!-- TemplateBeginRepeat name="customtag" -->
${RenderComponentPresentation(Field, rendercustomtagclosetemplate)}
<!-- TemplateEndRepeat -->
由于第二个循环关闭了第一个循环呈现的自定义标签,因此第二个循环应以相反的顺序运行。 (因为标签需要以相反的顺序关闭)。如何使用TemplateBeginRepeat以相反的顺序运行第二个循环?
最佳答案
没有内置的方法可以以相反的顺序遍历重复的项目。
如果customtag
是程序包中的一个数组项(通常是“组件”或“组件表示”的数组),则可以将包含相同项的列表以相反的顺序插入程序包,然后遍历该项。
<!-- TemplateBeginRepeat name="customtag_reversed" -->
如果您的
customtag
是字段,则无法使用,因为您不能将字段插入包中。在这种情况下,我建议创建一个自定义函数,以正确的顺序输出您的自定义标签,例如:@@RenderCustomTags('customtag', 'Order.Reverse')@@
更新
如果
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);
您将需要为每个链接的组件做一个循环:
list.Add(new ComponentPresentation(Component.Id, ComponentTemplate.Id));
而且,除了像在C#代码中对组件模板ID进行硬编码一样,您还可以考虑像在CWT中那样将其保留为空,并将其保留在DWT的
RenderComponentPresentation
调用中。
关于tridion - TemplateBeginRepeat以相反的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14160560/