Dynamic Documents with Handlebars: How to Print out All Questions/Answers in a Regular Section

 Note: This feature is a limited release for clients using Version 2 forms. 

This article is about using Handlebars to reference questions in custom PDF, Word, and HTML documents.  We recommend reading about Basic Question References and Advanced Question References before trying this. 

About

If a regular section contains a number of questions you would like to print out with exactly the same formatting, it can be most efficient to loop through them, rather than referencing each question individually.   

We will print out the below example into a document from a Regular Section.

 

 

Example Form

Here is a form with a Regular Section, named Common Area.  3 questions with Pass/Fail answers are shown (but the section can have many more and this example would still work).  

  [ top ]

 

HTML and Handlebars Example:

We will "loop" through all the answers in the section, printing each question/answer pair as a table row.

Note:  This example works for questions with simple, single property answers, like text fields or dropdowns.  Refer to our Basic References article to learn about referencing questions with other data types -- for example, photos need to have their "values" printed out in a specific way.

<table>

<!-- Below are the column headers -->
<thead>
<tr>
<th>Question</th>
<th>Rating</th>
</tr>
</thead>

<tbody>
<!-- This "each" is the beginning of the loop -->
{{#each dataRecord.pages.FacilityInspection.sections.CommonArea.answers}}

<!-- Below is a table row and cells, with the references (starting AFTER the answers container)-->
<tr>
<td>{{question}}</td><!--The question text -->
<td>{{values.[0]}}</td> <!--The question's answer -->
</tr>

<!-- This is the end of the loop-->
{{/each}}

</tbody></table>

 

Document Output Example:


How does it work?
 

The #each helper tells the document, for each question inside of "answers" in the CommonArea section, to print out a table row containing the two cells with the question text and the question answer.  When it is done with one "answer", it loops back and starts work on the next one, until all questions in the section have been printed. 

 [ top ]

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments