Tridion 模板开始按相反顺序重复

Tridion 模板开始按相反顺序重复,tridion,tridion-2011,Tridion,Tridion 2011,我需要使用TemplateBeginRepeat创建2个循环,其中我需要输出自定义标记 <!-- TemplateBeginRepeat name="customtag" --> ${RenderComponentPresentation(Field, rendercustomtagstarttemplate)} <!-- TemplateEndRepeat --> ${RenderComponentPresentation(字段,RenderConsToMT

我需要使用
TemplateBeginRepeat
创建2个循环,其中我需要输出自定义标记

<!-- TemplateBeginRepeat name="customtag" -->
    ${RenderComponentPresentation(Field, rendercustomtagstarttemplate)}
<!-- TemplateEndRepeat -->

${RenderComponentPresentation(字段,RenderConsToMTAGStartTemplate)}
输出一些html

<!-- TemplateBeginRepeat name="customtag" -->
    ${RenderComponentPresentation(Field, rendercustomtagclosetemplate)}
<!-- TemplateEndRepeat -->

${RenderComponentPresentation(字段,RenderConsToMTAGCloseTemplate)}

因为第二个循环关闭了第一个循环呈现的自定义标记,所以第二个循环应该以相反的顺序运行。(因为标签需要按相反顺序关闭)。如何使用TemplateBeginRepeat以组件的相反顺序运行第二个循环?

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


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

<!-- TemplateBeginRepeat name="customtag_reversed" -->

更新

如果
customtag
组件链接字段,则最好将这些链接的组件作为组件数组项添加到包中。努诺提供了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);

<> P>而不是硬编码C代码中的组件模板ID,也可以考虑将其在C中保留为空,并将其保持在<>代码> ReReDeamFrimeStudio中,就像您已经做的那样。在这里,问题似乎是Dreamweaver语法仅适用于最简单的编程任务。弗兰克和Nuno已经表明,将一些逻辑移到C模板中会有改进,但是你也应该考虑把这个输出的生成完全移到C的模板中。换句话说,一旦您需要使用DWT以外的东西,您的问题定义就会改变,因为现在描述的问题非常以DWT为中心


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

什么类型是
customtag
?它是字段吗?请注意${}只应用于异常,而不是默认情况下。它允许您在默认@@@之前首先计算(呈现)表达式。弗兰克,customtag是一个多值组件链接元数据字段,因此它是一个字段。然后,您必须创建自己的集合(在c#中创建ComponentArray,按相反顺序推送到包)。这里的示例-检查“按模板类型对组件进行分组”TBB或“获取同级组件”),你是对的,在这种情况下,将链接的组件推到包中可能会更好。我会更新我的答案。同意。鉴于这里调用了
RenderComponentPresentation
,这可能会生成大部分HTML,处理外观的C#可能不会输出太多HTML(可能只是
ul
li
s)。如果您希望以后能够在不需要Visual Studio的情况下修改源代码,我建议使用C#片段TBB作为DWT中复杂构造的替代方案。如果DWT调用它所在的模板会发生什么情况?:-)弗兰克,不过我没看到名单。这更像是作者想要的任何节点的嵌套:
内容的其余部分

”,其中div、p和span是
customtag`字段。那么也许C#只输出尖括号和属性?希望这个组件是为开发者或高级用户设计的。
//  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));