Using a For Loop is the preferred method for formatting Repeat Group values in your generated PDF and Word documents.

The basic syntax of a for loop is:

{% for [variable] in [repeat_group] %}

[content]

{% endfor %}

The [variable] set is required to access the information for each item in the repeat group.

Note:

  • The variable can be any name (preferably something unique)
  • repeat group  is the identifier of the group itself, e.g. fields.Subform.RepeatGroup

For example:

{% for site in fields.Sites %}

Site: {{site.Name}}
Rating: {{site.Rating}}
Comments: {{site.Comments}}
Photo: {{site.Photo}}

{% endfor %}


Note:  If all answers inside a repeat group are left blank, none of the content inside the for loop will be shown in the report. 

Check out the video below on adding Repeat Group For Loops to your custom template.

Default For Loop Placeholders: 

Default placeholders are provided in the list of placeholders found in your Destination Settings. For more information on obtaining these placeholders, click here.

Other Useful Examples

Tables:

To create a table with a for loop, make a table with a Header row and a Template row.

Put the {% for [variable] in [repeat_group] %} placeholder at the beginning of the first cell and then {% endfor %} at the end of the last cell.

You can then use the variable as you did in the above example in your table cells.

For example:

This will create a new row for each employee filling in the cells as you templated them.

Note: When the start of a for loop is placed inside a table cell, the end of the for loop will need to be placed inside a cell on the same row. If your repeat group data needs to span multiple rows, it's advised to wrap the for loop around a separate table. Please see the example below.

Numbering:

Numbers or bullets can be added to each row by using Word's Automatic Numbering/Bullet function. This can be placed before or after the for loop start.

The final report will look as follows:

Note: For more custom template options, like adjusting your image/signature size, click here.


Nested Loops:

It is possible to have repeat groups inside repeat groups. You just follow the syntax as with the previous examples.

For example, if your mobile form looks like this:

Your template should look something like the following:

Or use a table format:

The above template will repeat the Class Name for each item in the nested Repeat Group Students and will be displayed like this:

You can also use combination of text and table: 

For the basics on custom templating, check our this article.

Other Useful Articles:

If you have any questions or comments please send us a message at support@devicemagic.com.

Did this answer your question?