Why do I need to insert looped fields in my templates in Partner Tools?
You can apply this type of logic to a particular question in your final document Template (the document that your Respondents can download once they have answered to all questions in your Questionnaire).
If you want a particular question to be shown multiple times based on different conditions, you can insert looped fields in the Template.
- First, open your selected Template in Partner Tools (the Editor in which you will add Stencil code and insert looped fields will allow you to select direct questions by adding their ID or Value from the left-hand sidebar):
- To select a specific question and target it in your Stencil code, you need to click and copy the question ID that you want to loop and then Paste it into the template field on the right-hand side of the screen:
- Now you need to change the inserted question ID a bit, so it can be merged with the input from the questionnaire. To do so, remove the = (equal sign) and the [${index}] from the question's ID so it looks like this:
- Now insert for x in at the front of the question ID within the {% %} so it looks like this:
- Insert {%= x %} on the place where you want the looped answer to be inserted and end the {% for x in ...%} tag with an {% end %} tag. The final result should look like this, depending on the way you want the question to be inserted:
How can I add Looped fields with multiple indexes to my Templates?
The following Stencil will take every index output of the loop into consideration.
For example:
- We have a loop regarding breaks
- Firstly, the customer is asked how many breaks the employees have during a full workday
- Here, the loop is answered with 2
- Then, the two types of breaks are filled out:
We want the output to be:
- Lunch -- 30 minutes -- paid
- Afternoon -- 15 minutes -- paid
We will, therefore, use the following Stencil code to achieve that:
{%for idx, x in breaks.type%}
{%=breaks.type[idx] %} -- {%=breaks.length[idx] %} -- {%=lowercase(breaks.paidOrUnpaid[idx]) %}
{%end%}
breaks = the group name in the stencil code
breaks.type = here the data output is from the type of break, which is being filled in the first pictures.
Length = Same as above
paidOrUnpaid = here it will take the answer from the last question of whether the break is paid or unpaid.