Dynamic Documents with Handlebars: How to Print all Repeatable Section Entries in a Table

 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

Repeatable sections(link) 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. 

 

 

Example Form

Here is a form with a Repeatable Section (which collects Today's Date, and the Hours Worked).   Only one entry to 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 you enter 1 or 30 entries into the repeatable section. 

HTML and Handlebars Example:

<table>

<!-- Below are the column headers -->
<thead>
<tr>
<th>Date</th>
<th>Hours</th>
</tr>
</thead>

<tbody>
<!-- This "each" is the beginning of the loop -->
{{#each dataRecord.pages.HoursWorked.sections.Timesheet.rows}}

<!-- Below is a table row and cells, with the question references (starting AFTER the rows container)-->
<tr>
<td>{{pages.Timesheet.sections.TimesheetSection.answers.TodaysDate.values.[0]}}</td>
<td>{{pages.Timesheet.sections.TimesheetSection.answers.Hoursworked.values.[0].display}}</td>
</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 "row" that is 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. 

 

 

 

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

Comments