OpenWGA 7.0 - WebTML reference

WebTML tags » foreach

<tml:foreach type="itemvalue" >

Purpose:

Iterates over the values stored in an item or WebTML variable

Description:

The type="itemvalue" can be used to iterate over custom lists holding custom objects. This list must be stored in an item of the current context document or a WebTML variable for retrieval. The foreach tag will iterate over the elements of the list and its tag content will get rendered once for each element of it.

Use attribute item to specify the name of an item or WebTML variable holding the list you want to iterate over. The attribute currentvalue specifies the name of a variable which will hold the list value of the current iteration, so you can retrieve it from there inside the <tml:foreach> tag.

Examples:

The following example lists all attachments on the current context document. For that it stores the attachment names (retrieved via WGAPI) into a variable "attachments" which <tml:foreach type="itemvalue"/> iterates over. The name of the current attachment in the iteration is served as variable "attachment" and can be retrieved from inside the foreach body via that name.

<tml:script>
  attachments = content().getFileNames();
</tml:script>


<ul>
  <tml:foreach type="itemvalue" item="attachments" currentvalue="attachment">
    <li><tml:item name="attachment"/>: <tml:script expression="content().getFileSize(attachment)" format="#,##0"/> Bytes
  </tml:foreach>

</ul>