Handlebars - Advanced: How to Print all Repeatable Section Entries in a Table
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.
Available on the Advanced and Enterprise tiers:
About
Repeatable sections allow you to add multiple entries for the same set of questions, as many times as a user needs to. In documents, Repeatable sections are typically printed out in a table. This article explains how to do this most efficiently.
We will print out the below example into a document from a simple Repeatable Section A Repeatable Section is a subform that contains a set of related questions. The data captured is “repeating”, because the field user can complete the same subform more than once, which creates multiple entries..
Example Form
Here is a form with a Repeatable Section (which collects Today's Date, and the Hours Worked). Only one entry in the repeatable section is shown here to save on space.
One "row" in the above data structure is one repeatable section entry. You will want to loop through the rows to print them all. In the example below, we will print each "row" in the repeatable section into its own row in the table. This will work whether there are one or many entries in the repeatable section.
HTML and Handlebars Example:
<table> |
Document Output Example:
How does it work?
The #each helper tells the document, for each "row" that it finds in the Repeatable section, to print out a table row containing the two cells with the question references. When it is done with one "row", it loops back and starts work on the next row, until all rows have been printed.