tridion - TemplateBeginRepeat以相反的顺序

标签 tridion tridion-2011

我需要使用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/

相关文章:

Tridion Schema 锁定到特定组

Tridion UI 2012 - 错误 "The item tcm:280-29837-64 does not exist."

tridion - SDL Tridion Content Porter 2009 SP1 - 同步内容

ASP.Net CMS 推荐,Orchard、Sitefinity、Umbraco 还是 N2?

Tridion:页面已取消发布时出现 "The item is published. Unable to delete Page."错误

tridion - 尝试将二进制文件部署到已存储不同二进制文件的位置

Tridion RTF 文本选择

tridion - 如何在 Tridion 中获取所选项目的 itemxml

tridion - SmartTarget FredHopper 日期/触发器配置

tridion - 获取当前登录用户的 session - 自定义页面