Tridion:在链接组件上循环时组件模板问题
你好, 我在链接组件上循环时遇到问题。Tridion:在链接组件上循环时组件模板问题,tridion,tridion-2011,tridion-content-delivery,Tridion,Tridion 2011,Tridion Content Delivery,你好, 我在链接组件上循环时遇到问题。 我创建了带有产品项的EmailSetup(View)组件。 产品组件具有架构(EmailBlockWithCode)。 产品:-Code=“wms_III” -项目:-Key=“ProductKey”-Content=“ProductContent” -CallToAction:-Item:-Key=“BluetoothKey” -Content=“BluetoothContent” 当我使用代码循环此组件时: <products>
我创建了带有产品项的EmailSetup(View)组件。
产品组件具有架构(EmailBlockWithCode)。
产品:
- -Code=“wms_III”
- -项目:
- -Key=“ProductKey”
- -Content=“ProductContent”
- -CallToAction:
- -Item:
- -Key=“BluetoothKey”
- -Content=“BluetoothContent”
<products>
<!-- TemplateBeginRepeat name="Component.Fields.Product" -->
@@GetComponent(Field,'Product')@@
<product name="@@Product.Code@@">
<!-- TemplateBeginRepeat name="Product.Fields.Item" -->
<@@Product.Fields.Item.Key@@><![CDATA[@@Product.Fields.Item.Content@@]]></@@Product.Fields.Item.Key@@>
<!-- TemplateEndRepeat -->
<!-- TemplateBeginRepeat name="Product.Fields.CallToAction" -->
@@GetComponent(Field,'CallToAction')@@
<@@CallToAction.Fields.Item.Key@@><![CDATA[@@CallToAction.Fields.Item.Content@@]]></@@CallToAction.Fields.Item.Key@@>
<!-- TemplateEndRepeat -->
</product>
<!-- TemplateEndRepeat -->
</products>
<products>
<product name="wms_III">
</product>
</products>
<!-- TemplateBeginRepeat name="Component.Fields.Product" -->
@@GetComponent(Field,'Product')@@
<!-- TemplateBeginRepeat name="Product.Fields" -->
@@Field.Name@@
<!-- TemplateBeginRepeat name="Field.Values" -->
<!-- TemplateBeginIf cond="Field.ContentType = 'text/plain'" -->
@@RenderComponentField(FieldPath, TemplateRepeatIndex)@@
<!-- TemplateEndIf -->
<!-- TemplateBeginIf cond="Field.ContentType = 'tridion/field'" -->
<!-- TemplateBeginRepeat name="Field.Fields" -->
@@Field.Name@@
<!-- TemplateBeginRepeat name="Field.Values" -->
@@RenderComponentField(FieldPath, TemplateRepeatIndex)@@
<!-- TemplateEndRepeat -->
<!-- TemplateEndRepeat -->
<!-- TemplateEndIf -->
<!-- TemplateEndRepeat -->
<!-- TemplateEndRepeat -->
我的输出是:
<products>
<!-- TemplateBeginRepeat name="Component.Fields.Product" -->
@@GetComponent(Field,'Product')@@
<product name="@@Product.Code@@">
<!-- TemplateBeginRepeat name="Product.Fields.Item" -->
<@@Product.Fields.Item.Key@@><![CDATA[@@Product.Fields.Item.Content@@]]></@@Product.Fields.Item.Key@@>
<!-- TemplateEndRepeat -->
<!-- TemplateBeginRepeat name="Product.Fields.CallToAction" -->
@@GetComponent(Field,'CallToAction')@@
<@@CallToAction.Fields.Item.Key@@><![CDATA[@@CallToAction.Fields.Item.Content@@]]></@@CallToAction.Fields.Item.Key@@>
<!-- TemplateEndRepeat -->
</product>
<!-- TemplateEndRepeat -->
</products>
<products>
<product name="wms_III">
</product>
</products>
<!-- TemplateBeginRepeat name="Component.Fields.Product" -->
@@GetComponent(Field,'Product')@@
<!-- TemplateBeginRepeat name="Product.Fields" -->
@@Field.Name@@
<!-- TemplateBeginRepeat name="Field.Values" -->
<!-- TemplateBeginIf cond="Field.ContentType = 'text/plain'" -->
@@RenderComponentField(FieldPath, TemplateRepeatIndex)@@
<!-- TemplateEndIf -->
<!-- TemplateBeginIf cond="Field.ContentType = 'tridion/field'" -->
<!-- TemplateBeginRepeat name="Field.Fields" -->
@@Field.Name@@
<!-- TemplateBeginRepeat name="Field.Values" -->
@@RenderComponentField(FieldPath, TemplateRepeatIndex)@@
<!-- TemplateEndRepeat -->
<!-- TemplateEndRepeat -->
<!-- TemplateEndIf -->
<!-- TemplateEndRepeat -->
<!-- TemplateEndRepeat -->
所以我的问题是代码没有在“item”(key=ProductKey;content=ProductContent)上循环
我发现一个函数迭代多值嵌入字段,但这也不会循环我的产品。代码:
<products>
<!-- TemplateBeginRepeat name="Component.Fields.Product" -->
@@GetComponent(Field,'Product')@@
<product name="@@Product.Code@@">
<!-- TemplateBeginRepeat name="Product.Fields.Item" -->
<@@Product.Fields.Item.Key@@><![CDATA[@@Product.Fields.Item.Content@@]]></@@Product.Fields.Item.Key@@>
<!-- TemplateEndRepeat -->
<!-- TemplateBeginRepeat name="Product.Fields.CallToAction" -->
@@GetComponent(Field,'CallToAction')@@
<@@CallToAction.Fields.Item.Key@@><![CDATA[@@CallToAction.Fields.Item.Content@@]]></@@CallToAction.Fields.Item.Key@@>
<!-- TemplateEndRepeat -->
</product>
<!-- TemplateEndRepeat -->
</products>
<products>
<product name="wms_III">
</product>
</products>
<!-- TemplateBeginRepeat name="Component.Fields.Product" -->
@@GetComponent(Field,'Product')@@
<!-- TemplateBeginRepeat name="Product.Fields" -->
@@Field.Name@@
<!-- TemplateBeginRepeat name="Field.Values" -->
<!-- TemplateBeginIf cond="Field.ContentType = 'text/plain'" -->
@@RenderComponentField(FieldPath, TemplateRepeatIndex)@@
<!-- TemplateEndIf -->
<!-- TemplateBeginIf cond="Field.ContentType = 'tridion/field'" -->
<!-- TemplateBeginRepeat name="Field.Fields" -->
@@Field.Name@@
<!-- TemplateBeginRepeat name="Field.Values" -->
@@RenderComponentField(FieldPath, TemplateRepeatIndex)@@
<!-- TemplateEndRepeat -->
<!-- TemplateEndRepeat -->
<!-- TemplateEndIf -->
<!-- TemplateEndRepeat -->
<!-- TemplateEndRepeat -->
@@GetComponent(字段,“产品”)@@
@@字段名@@
@@RenderComponentField(字段路径、TemplateRepeatIndex)@@
@@字段名@@
@@RenderComponentField(FieldPath,TemplateRepeatIndex)@@
那么在DW函数将组件推入包中后,您似乎无法访问包中的组件 有了,您的代码大概是这样的,您考虑过改用它吗
这可能与模板的执行方式有关。首先渲染最内部的重复区域,然后渲染器向外工作 因此,在内部重复区域中,您还无法访问先前获得的组件 是的,这一点也不直观,但它就是这样工作的
<products>
<!-- TemplateBeginRepeat name="Component.Fields.Product" -->
@@RenderComponentPresentation(Field, "tcm:75-72162-32")@@
<!-- TemplateEndRepeat -->
</products>
您可以做的是遍历所有链接的组件,并使用在DWT之前执行的.NET TBB中的字段名将它们推入包中
我使用此代码修复了此问题。不是最好的,但它很有效
<products>
<!-- TemplateBeginRepeat name="Component.Fields.Product" -->
@@RenderComponentPresentation(Field, "tcm:75-72162-32")@@
<!-- TemplateEndRepeat -->
</products>
@@渲染组件表示(字段“tcm:75-72162-32”)@@
renderComponentPresentation将使用以下内容加载另一个dwt:
<product name="@@Component.Fields.Code@@">
<!-- TemplateBeginRepeat name="Component.Fields.Item" -->
<@@Field.Key@@><![CDATA[@@Field.Content@@]]></@@Field.Key@@>
<!-- TemplateEndRepeat -->
<!-- TemplateBeginRepeat name="Component.Fields.CallToAction" -->
@@GetComponent(Field,'CallToAction')@@
<@@CallToAction.Fields.Item.Key@@><![CDATA[@@CallToAction.Fields.Item.Content@@]]></@@CallToAction.Fields.Item.Key@@>
<!-- TemplateEndRepeat -->
</product>
@@GetComponent(字段“CallToAction”)@@
没错,我们无法访问包中的组件。我安装了DGX&代码运行正常。但是代码“”仍然不想循环“Item”,因为它不会查看包中不存在的组件的字段。不确定如何解决这个问题,我没有为此用例构建DGX,也不确定它是否有效-在重复和条件中使用DGX时字段中的混合报告这很奇怪,因为如果我执行“@@Count(field,'Item')@”它说有2个计数@@Get('Product.Fields.Item[1].Key')返回其中的值!但当我循环时,DW中的循环逻辑是相当复杂的——据我当时所知,它是不可扩展的。这可能同时发生了变化(我在大约4年前编写了DGX),但没有时间或需要回到itBert,您的代码是这样的吗?[repeat]获得产品[repeat]从产品中获取价值[/repeat][/repeat]也不起作用,我在问题中发布了一个解决方案。无论如何,在您的新方法中,您不会遇到渲染顺序问题,所以这可能是原因?或者为什么没有?修复了。检查我的回答伯特,当这确实解决了您的问题时,请将其标记为答案,以便此问题结束。:)