The Tridion practice page that Neil referred to is a good reference. But that page shows how to generically iterate over all embedded fields. In cases where you know the field name, things get a bit easier. In you case, this is all that is needed in your DWT:
<!-- TemplateBeginRepeat name="body" -->
<!-- TemplateBeginRepeat name="Field.value" -->
<div>@@RenderComponentField(FieldPath+".value",
TemplateRepeatIndex)@@ </div>
<!-- TemplateEndRepeat -->
<!-- TemplateEndRepeat -->
Line by line:
- Iterate over the values of the
body
field of your Component - Iterate over the values of the
value
subfield of yourbody
embeddable schema - At this stage the
FieldPath
refers to the currentbody
value, sobody[0]
,body[1]
, etc. andTemplateRepeatIndex
is the index of the currentvalue
. So we can construct the correctRenderComponentField
call with this knowledge.
Example
I have a Component with two body
fields, each with two value
fields. So the XML is:
<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>
The output from the above DWT on this Component is:
<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>
Debugging these situations
Many people have problems writing constructs like these. I am no exception, I have just found that I can get most cases working by knowing that the crucial variables are: Field
, FieldPath
and TemplateRepeatIndex
. When in doubt, simply embed this fragment into your DWT inside every TemplateBeginRepeat
.
(FieldPath=@@FieldPath@@, TemplateRepeatIndex=@@TemplateRepeatIndex@@)