Handlebars - Basic Question References
Available on the Advanced and Enterprise tiers:
- About
- Referencing the Answer to a Question
- Referencing Multiple Answers Efficiently using "With"
- Questions with Multiple Properties
- Image, Sketch Pad, and Signature Questions
About
Handlebars is a templating language that can be used to reference answers from a form submission. These references can be embedded within HTML, or whatever language you are using to define how a document should be structured.
It is used with the following features:
- Building custom documents as PDF, Word, or HTML
- Building Handlebars Documents to create a different document type
This topic describes how to reference single answers to questions, wherever they are in the form.
Read about Handlebars: Advanced Question References if you are interested in building more dynamic document templates that don't require you to reference every question individually.
Referencing the Answer to a Question
A basic reference can be used in most cases where you are mapping a single answer from a form into a document. In these cases, you do not need to understand the full structure of a form, and you move the questions to different pages or sections in the form without affecting the document.
If you are building a custom PDF, Word, or HTML Document using Handlebars, the first part under Reference Data in the document editor screen will show you which questions you can reference.
Example Form
This is a sample describing the basic data structure of a form. (Highlighting added for the purposes of documentation).
-
All questions in the form are wrapped in the "Answers" node (shown here in orange).
-
The parts highlighted in blue here are the questions, followed by a sample answer.
The question reference shown here is based on the Unique ID, with any spaces or special characters removed.
Example Handlebars Reference
You can have the answer to "AccountName" printed in your document using the following reference:
{{answers.AccountName.[0]}}
Result
ABC Construction
How does it work?
The final part of the reference (after the last ".") is what will get printed in the document; everything before it tells the document what path to follow through the data structure in order to find it.
The reference above tells the document to:
- Look for the "answers" node
- Look for "AccountName" inside of it
- Look inside of AccountName, for the first value wrapped in square brackets
Referencing Many Questions Efficiently (using "#with")
If you are referencing many questions, you can save yourself a bit of typing. You can do this by using the Handlebars "with" helper.
Example Reference
Instead of referencing multiple questions like:
{{answers.AccountName}}<br/>
{{answers.Contact}}<br/>
{{answers.City}}<br/>
{{answers.State}}<br/>
You can do this:
{{#with answers}}
{{Contact.[0]}}<br/>
{{City.[0]}}<br/>
{{State.[0]}}<br/>
{{/with}}
Result
Jane Doe
123 Avenue Street
New York
How does it work?
The #with helper tells the document to look inside of "answers" for every reference that comes after it, until it hits the closing /with.
Questions with Multiple Properties
Answers with certain data types have multiple properties. The properties either combine together to provide a full answer to a question, or the properties contain multiple ways to reference the same answer (for example, a date/time question will contain the same date/time shifted into different timezones).
When an answer has multiple properties, you can choose which of these properties you want to be used in your document.
Example Form
This form has two questions.
- The first is a Date, which only has one answer.
- The second is a Duration, which has two properties (in this case, they display the same answer, but in different units - milliseconds, or hours/minutes/seconds).
Example Handlebars Reference
{{answers.Hoursworked.[0].display}}
Result
00:1:00
Image, Sketch Pad, and Signature questions
Image, Sketch Pad, and Signature questions all have multiple properties. Because they can be a little difficult to reference, it's easiest to use our custom Handlebars helper for images.
Questions that allow a single image, sketch or signature
For Signature questions, or for Image and Sketch Pad questions set up to allow only one image, you can get the image to print out with the following reference. Specify the height or width in pixels, and images will auto-scale to maintain proportions, whether they were taken portrait or landscape.
To support existing integrations, some items will continue to use “prontoforms” or “pf” in the domain or code.
For more detailed information about what’s changing, visit https://support.truecontext.com/hc/en-us/articles/19516168513556
{{pf:img answers.PhotoUniqueID.[0] height=200}}
Questions that allow multiple images or sketches
Image or Sketch Pad questions can be set up to allow multiple images. To print all collected images, use the following reference.
{{#each answers.PhotoUniqueID}}
{{pf:img this height=200}}
{{/each}}
Other types of attachment-based questions
We ignore references to the bytes
property for Audio Recording, Document Editor, and File Upload answers.
Tip:If you want to reference or display uploaded images, set up your form with Image, Sketch Pad, or Signature questions.