Handlebars - Advanced: How to Print out All Questions/Answers in a Regular Section
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 A Regular Section is a set of related questions grouped together for easy reference. The data captured is “non-repeating”. That is, field users enter a single instance of each answer. 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”. Three questions with Pass/Fail answers are shown (but the section can have more, and this example would still work).
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>
|
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 gets the next one, until all questions in the section have been printed.