Using Handlebars - Basic Question References

 

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

 

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:

In this document, you will read about how to reference single answers to questions, wherever they are in the form.

Read about 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 Question Label, 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

[ top ]

 

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.  Read more about Handebars helpers.  

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

[ top ]

 

 

Questions with Multiple Properties

Some question types have multiple properties that combine together to provide an answer to a form.  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

[ top ]

 

 

Image/Sketchpad/Signature Questions

Photos, Sketches, and Signatures are other types of question that has 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 Image/Sketchpad 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, and images will auto-scale to maintain proportions, whether they were taken portrait or landscape. 

 {{pfimg answers.PhotoUniqueID.[0] height=200}}

 Questions that allow Multiple Images or Sketches

Image or Sketchpad Questions can be set up to allow multiple images.  To print all collected images, use the following reference. 

{{#each answers.PhotoUniqueID}}
{{pfimg this height=200}}
{{/each}} 

 [ top ]

 

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

Comments