Adding an iteration element
The
iteration element is available only in version 2 templates.Before you begin
- Create a section of content you want to duplicate.
- Create a variable.
About this task
The contents of an iteration block will always be published at least once, regardless of the do-while statement.
In the first stage, the data that is used in the condition must change so that there is a finite number of steps. This condition is what makes the processing of the sections end and not continue to loop. In step 5 of the example below, the condition is that the teamList variable is not empty. So the condition is true so long as there are data entries for the teamList variable. When there are no more data entries, the condition is false and the repetition ends.
To have the queries executed multiple times, add a dynamic Data Source Configuration element inside the loop container to force the queries to be initialized more than one time.
Procedure
Example
- Create an external variable named teamList.
- Create an external variable named currentMember.
- Create a table element and apply a condition:
- Add a
Table element to the template content editor. - Enter 1 column and 2 rows.
- Right-click the Table element and select .
- Select the teamList variable.
- For the Left operand, select the teamList variable.
- For the Operator, select Not equal to.
- For the Right operand, do not enter a value.
- Click Add. The script result is: teamList != ""
- Click OK.
- Add a
- In the first cell, add a heading for column:
- Add a
Text element to the cell. - Double-click the Text element to open the content editor.
- Enter a heading name as Team Member List.
- Click OK.
- In the Properties view, select the Font tab.
- Click Bold property.
- Select True and click OK.
- Add a
- Add the Iteration element:
- Drag the
Iteration element from the Palette view and place
it between the rows of the table. - Select the Iteration element.
- In the Properties view, enter this script for the do while condition property: teamList != ""
- Add two
Container elements in the Iteration element. The
first Container is used to calculate the first name from the list
to be used in the current row. The second Container is used to end
the loop so it does not continue unnecessarily. - Drag the second row and its contents into the Iteration element and place it after the container elements.
- Drag the
- Assign a variable to the first container element:
- Right-click the first Container element.
- Select
- Click Add.
- Select the currentMember variable and click OK.
- Select the Script Expression tab.
- Select the teamList variable and enter the
script:
var pos = teamList.indexOf( ","); if ( pos >=0) { // get the first member ( till the first comma) teamList.substr( 0, pos); } else { // last member teamList; } - Click OK and OK.
- Assign a variable to the second container element:
- Right-click the second Container element.
- Select
- Click Add.
- Select the teamList variable and click OK.
- Select the Script Expression tab.
- Select the teamList variable and enter the
script:
var pos = teamList.indexOf( ","); if ( pos >=0 && pos < teamList.length) { // get the first author ( till the first comma) teamList.substr( pos + 1); } else { // last member, remove it "" }
- Drag the currentMember variable from the Outline view to the cell in the second row.
- Test the output.