我正在使用SDL Tridion 2011 SP1中的DWT TBB.
我有一个嵌入式字段"body",它是多值的.在这个嵌入式字段中,我有一个更简单的文本字段"值",它再次是多值的.
要渲染"value"字段,我必须使用两个重复循环.
但我无法区分两个循环的Indeces.
我写的如下.
<!-- TemplateBeginRepeat name="Component.Fields.body" -->
<!-- TemplateBeginRepeat name="Component.Fields.body[${TemplateRepeatIndex}].value" -->
<div>@@RenderComponentField("Fields.body[${TemplateRepeatIndex}].value", TemplateRepeatIndex)@@ </div>
<!-- TemplateEndRepeat -->
<!-- TemplateEndRepeat -->
Run Code Online (Sandbox Code Playgroud)
我无法渲染字段.
任何人都可以帮助如何处理DWT TBB中的多个嵌套区域.
谢谢.
Fra*_*len 15
Neil提到的Tridion练习页面是一个很好的参考.但该页面显示了如何一般地迭代所有嵌入字段.如果您知道字段名称,事情会变得容易一些.在您的情况下,这就是您的DWT中所需的全部内容:
<!-- TemplateBeginRepeat name="body" -->
<!-- TemplateBeginRepeat name="Field.value" -->
<div>@@RenderComponentField(FieldPath+".value",
TemplateRepeatIndex)@@ </div>
<!-- TemplateEndRepeat -->
<!-- TemplateEndRepeat -->
Run Code Online (Sandbox Code Playgroud)
逐行:
bodyComponent 的字段值value子字段的值bodyFieldPath指的是当前body值,等等body[0],body[1]并且TemplateRepeatIndex是当前的索引value.所以我们可以RenderComponentField用这些知识构建正确的调用.我有一个包含两个body字段的Component ,每个value字段有两个字段.所以XML是:
<Content xmlns="uuid:8841d68e-7b1b-45cd-a6d6-7e7da5de3ef9">
<body>
<value>body1.value1</value>
<value>body1.value2</value>
</body>
<body>
<value>body2.value1</value>
<value>body2.value2</value>
</body>
</Content>
Run Code Online (Sandbox Code Playgroud)
上面这个组件的DWT输出是:
<div><tcdl:ComponentField name="body[0].value"
index="0">body1.value1</tcdl:ComponentField></div>
<div><tcdl:ComponentField name="body[0].value"
index="1">body1.value2</tcdl:ComponentField></div>
<div><tcdl:ComponentField name="body[1].value"
index="0">body2.value1</tcdl:ComponentField></div>
<div><tcdl:ComponentField name="body[1].value"
index="1">body2.value2</tcdl:ComponentField></div>
Run Code Online (Sandbox Code Playgroud)
许多人在编写像这样的结构时遇到了问题.我也不例外,我刚刚发现,我能得到大多数情况下知道的关键变量是工作:Field,FieldPath和TemplateRepeatIndex.如果有疑问,只需将此片段嵌入到您的DWT中TemplateBeginRepeat.
(FieldPath=@@FieldPath@@, TemplateRepeatIndex=@@TemplateRepeatIndex@@)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3919 次 |
| 最近记录: |