Iterating through a list or a table in a DOCX template
By using for
statements inside embedded tags, you can iterate through arrays of data to populate ordered and unordered lists and tables in your DOCX template.
For the examples that we will describe here, we will use the following merge parameters, which represent an array of names:
"merge_parameters": {"names": [{"first": "John", "last": "Doe"}, {"first": "Jane", "last": "Smith"}]}
Embedding ordered and unordered lists
Embedding ordered lists
To embed an ordered list into your DOCX template, insert the following into your document:
{% for name in names %}
1. {{name.last}}
{% endfor %}
Embedding unordered lists
To embed an unordered list into your DOCX template, insert the following into your document:
{% for name in names %}
• {{name.last}}
{% endfor %}
Embedding tables
To embed a table into your DOCX template, insert the following into your document:
First Name | Last name {% for name in names %} |
---|---|
{{name.first}} | {{name.last}}{% endfor %} |
To see lists and tables in action, check out how to build a full-featured DOCX template.
Updated 11 months ago