The cx:foreach element repeats its content for each item in the list given. Like in: 

<cx:foreach list='("first", "second", "last")'>

       <cx:write value="$item"/>

</cx:foreach>

Often the value of the list attribute will be a variable of the list type, like for instance a list of candidate objects. But as previous example shows a constant string with a list format is automatically transferred into a list (items in the lilst are of type string). 

When using a variable do not forget to precede the variable name with a dollar sign $:

<cx:fetch list="employees" entity="CREmployee">

 <cx:foreach item="e" list="$employees">

   <cx:write value="$e.informalName"/>

 </cx:foreach>

</cx:fetch>

Attributen

The following table contains all attributes available with the cx:foreach element. Obligatory attributes are printed bold.

Batch

The batch attribute only works in combination with the count attribute.The cx:for-each loop starts of with the item at list index batch * count

Remarks

  • Within the cx:for-each content the variable item contains the current list item. Or define a name for this variable yourself by using the item attribute.
  • Within the cx:for-each content the variable index contains the list index of the current item. Or define a name for this variable yourself by using the index attribute.

Note :
That the list index starts with 0 and therefor ends with n - 1 (n being the number of items in the list).

Did this answer your question?