Access the Templates tab in the form administration.
Then click on New Template.
Assign a name to your template.
Once created, access your template by clicking on its name.
The option to upload a template will then be displayed.
In Microsoft Word or Excel, the values of the form fields can be used as template parameters. Copy field labels from the template settings.
To insert a field in the Word or Excel template, simply paste the field label in double brackets {{}}.
Print table-type fields
To print table-type fields in the template, you have to create a table in the Word document which must have 3 columns:
Table header
In the first cell of the table in Word, you have to open the iteration by the table values.
{%tc for col in metadata_invoice_items.col_labels %}
metadata_invoice_item is the label of the table type field, which must be copied like any other field.
Then, in the continuous cell put:
{{ col }}
In the template, one column will be generated for each defined in the table field.
Finally, in a third cell, the header loop shall be closed.
{%tc endfor %}
Table body
Then, in a new row, open the loop that will loop through the values in the table.
{%tr for item in metadata_invoice_items.content %}
metadata_invoice_item is the label of the table field, to be copied like any other field.
Then, in the next row, the first cell, open a new loop:
{%tc for col in item.cols %}
Then, in the continuous cells put:
{{ col }}
In a third cell, the header loop shall be closed.
{%tc endfor %}
Finally, in a new row, close the first loop.
{%tr endfor %}
As a result of the above example, a table is obtained:
From the table field:
Print items from tables
To print items from the rows and columns of a table in the template, first open the loop that will iterate over the items in the template, replacing "field_tag" with the label of the table field:
{% for item in field_tag.content %}
Then add the text that will be fixed for each iteration and the column labels, where {{ items.cols.num_de_col }} will be replaced with the value of that column number within each row of the table:
- This is an example text where {{ items.cols.0 }} is the value of column 1, and {{ items.cols.1 }} is the value of column 2.
Closing the loop with:{% endfor %}
Printing JSON-type fields as tables
The data structure below is saved in a JSON-type field on Athento.
And the aim is to print one table that includes the payment data for each contract, as shown below.
It is possible to print this information by using a Word template. To do so, we need to open a for statement and iterate through all the contracts included in the JSON data.
{% for contract in my_json_file.contracts %}
{% endfor %}
Once we have iterated through the contracts, we need to also iterate through the payments in each contract.
{% for contract in my_json_file.contracts %}
{% for instalment in contract.Instalment %}
{% endfor %}
{% endfor %}
To print a contract ID we use:
{{ contract.ContractId }}
To print a payment date, we use:
{{ Instalment.date }}
The previous structure helps us to loop through the data contained in the JSON-type field, regardless of the format we want to give it. If what we want is to print a table, the syntax changes slightly:
Additional documentation about template syntax
Comments
0 comments
Please sign in to leave a comment.