SKIP AHEAD TO
Why use the loop function in rich style documents?
How can you create looping sections of text?
Basic use of loops in a template
Bulleted and numbered lists
Multiple List references within a Loop section
Insert Dynamic Table Row by Condition
Insert Dynamic Table Row by Loop
Why use the loop function in rich style documents?
The loop function can allow items in a list to be dynamically displayed based on the end user's responses in numbered or dotted format or even within a sentence. It can also be used to insert a dynamic table that only displays what is necessary based on the end user's responses. See examples below on the common use cases of loop functions.
How can you create looping sections of text?
You can create looping sections of text that make reference to a LIST variable in the application.
To start a Loop section, type {{LOOP(List reference)}}
To end a Loop section: {{ENDLOOP(List reference)}}
To access the entries in a list, add the ".item" suffix to a List reference i.e. (List reference.item) (This takes the place of VAL1 from Document Loops).
Without the ".item" suffix, only the length of a list will be considered by a condition, not the entries within the list. Also note that when referencing a list within a Loop section, a difference list can be referred to than the one used in {{LOOP(List reference)}}.
Basic use of loops in a template
Assume LIST12 contains 3 items; apples, oranges, pears
{{LOOP(LIST12)}} This grocery store stocks {{LIST12.item}}
{{ENDLOOP(LIST12)}}
This will display:
This grocery store stocks apples.
This grocery store stocks oranges.
This grocery store stocks pears.
Bulleted and numbered lists
To display a numbered list, using the above example, add the following:
This grocery store stocks:
{{LOOP(LIST12)}} 1. {{LIST12.item}} {{ENDLOOP(LIST12)}}
This will display:
This grocery store stocks:
- apples
- oranges
- pears
Note: When adding a numbered list, use the numbered list functionality in Word. The same applies for a bulleted list.
Multiple List references within a Loop section
Referring to the above example, if the entries for fruits that the grocery store stocked (entries you want to print) were instead stored in LIST11, but you wanted a number of Loop iterations equal to the number of entries in LIST12, write:
{{LOOP(LIST12)}}
This grocery store stocks:
1. {{LIST11.item}}
{{ENDLOOP(LIST12)}}
If LIST11 again has 3 entries, but LIST12 only has 2, the following will display:
This grocery store stocks:
- apples
- oranges
If LIST12 has 3 or more entries, all entries in LIST11 will be displayed.
Insert Dynamic Table Row by Condition
To emulate the App’s dynamic table Inside the document, you can either use conditions or the loop functions. Conditions are typically used this way for one instance of a dynamic table row while loops are used for multiple dynamic table rows.
To insert a dynamic row using conditions:
- Write an opening logic tag in the first column
- Enter the text or reference variables across the columns in the same row
- Write a closing logic tag to signify the end of the dynamic row
Column 1 | Column 2 |
{{#LikeDog=="Yes"}}Please specify what breed of dogs you like: |
{{DogBreed}}{{/}} |
Limitation: You cannot close logic tags in the MIDDLE of a table cell that is different to the cell with the opening logic tag. For example, the below table will be invalid since in column 2, there are other items after the closing tag {{/}} (bolded)
Column 1 | Column 2 |
{{#LikeDog=="Yes"}}Please specify what breed of dogs you like: | {{DogBreed}}{{/}}{{#DogBreed=="Other"}} – {{Other_DogBreed}}{{/}} |
Insert Dynamic Table Row by Loop
To emulate the App’s dynamic table Inside the document with multiple rows using loops, you must:
- Create a regular table in inside your Word document
- Insert a LOOP function for the dynamic with the appropriate syntax. See syntax below
- Insert the variables from the dynamic row in the TABLE block using double curly brackets with a “.item” suffix (e.g. {{TBL14_D3.item}})
Loop function syntax:
To enable a dynamic row in the table inside the document, you must use a LOOP function for the row under the header of the table. For a LOOP function to work, a LIST variable must be referenced at the start (i.e. LOOP) and end (i.e. ENDLOOP) of the function. All table variables in the dynamic row must include the suffix “.item” (e.g. {{TBL14_B2.item}}). Learn more about table variables.
i.e.
Column 1 | Column 2 | Column 3 | Column 4 |
{{LOOP(LIST#)}}{{insert table variable.item}} | {{insert table variable.item}} | {{insert table variable.item}} | {{insert table variable.item}}{{ENDLOOP(LIST#)}} |
Example of Dynamic table rows:
For example, in the case of the screenshot below, we have referenced a dynamic list (LIST10) inside cell A2 of TABLE block (TBL14), therefore the syntax for the dynamic table row is LOOP(TBL14_A2) and ENDLOOP(TBL14_A2). Any variables referenced within the loop (i.e. the dynamic row - in this case, row 2 of TBL14) must add the suffix “.item” (e.g. {{TBL14_B2.item}}).
TBL14 structure (in App):
Rich Document Implementation:
Related Articles
- Reference Variables in DOC GEN Documents
- Conditions in DOC GEN Documents
- Add Uploaded Images to DOC GEN Documents
- Add a DOC GEN document to your App