Data Types
Learn how to work with different data types in your templates.
Data can be sent to Documint in several different types. Below is a list of those types and how to use them in your templates.
Strings are simply text data.
Template
Data
Result
{{customer_name}}
{
customer_name: "Acme Co."
}
Acme Co.
Numbers are integers or floating-point decimals.
Template
Data
Result
{{total_amount}}
{
total_amount: 149.99
}
149.99
You can format numbers using the
$number
format. Booleans are values that are either
true
or false
. They can not contain any values other than these.Template
Data
Result
{{is_fragile}}
{
"is_fragile": true
}
true
Objects are groups of key-value pairs. Unlike strings, numbers, and booleans, objects have nested properties that you access using dot notation. For example, let's say that we have an object named
address
with 4 properties; street1
, city
, state
, and country
and we want to display the street1
property we'll use the following token {{ address.street1 }}
. If we were to use a token with the name of the object (eg. {{ address }}
) this would result in [object Object]
.Template
Template
Result
{{address.street1}}
{
"address": {
"street1": "123 Main St.",
"city": "New York",
"state": "NY",
"country": "United States"
}
}
123 Main st.
If a variable is set to the name of the object rather than a property of that object, it will render as
[object Object]
. For example, if the variable in the template in the example above was {{ address }}
instead of {{address.street1}}
this would render as [object Object]
because the entire address
object is trying to be rendered instead of a property (eg. street1
) of that object. An array is a list of items. This can be a list of any other data type, including objects (an array of objects is called a collection) and other arrays. Arrays are what you will use to repeat/loop elements in your template.
Template
Data
Result
{{movies[0]}}
{{movies[2]}}
{
"movies": [
"Cinderella",
"Avatar",
"Million Dollar Baby",
"Toy Story"
]
}
Cinderella
Million Dollar Baby
Template
Data
Result
{{#each movies }}
Movie: {{this}}
{{/each}}
{
"movies": [
"Cinderella",
"Avatar",
"Million Dollar Baby",
"Toy Story"
]
}
Movie: Cinderella
Movie: Avatar
Movie: Million Dollar Baby
Movie: Toy Story
You can also repeat an element for each item in an array. To learn more check out Repeating Elements
[object Object]
ErrorSimilar to objects you cannot display the array itself. If you do, this will result in
[object Object]
being displayed. Unlike objects, arrays must be either looped over to display each item in the array or display a specific item in the array.A collection is an array of objects. Because it's an array, it must be looped over like arrays. Because the items of the array are objects you must display the properties of the object and not the object itself.
Example:
In this example, we have a list of order line items that we want to display as a table. To do this we will loop over each item in the list of line items using the
#each
function. When looping over a list of objects, you can access the properties of that object directly since variables within a loop are within the context of the current item.
Template
Data
Result
{{#each line_items}}
{{qty}} x {{name}} @ {{$number amount "$0,0.00"}} ea.
{{/each}}
{
"line_items": [
{
"name": "Sample widget 1",
"price": 50,
"quantity": 2,
"amount": 100
},
{
"name": "Sample widget 2",
"price": 1200,
"quantity": 1,
"amount": 1200
},
{
"name": "Sample widget 3",
"price": 10,
"quantity": 50,
"amount": 500
}
]
}
2 x Sample widget 1 @ $100 ea.
1 x Sample widget 2 @ $1,200 ea.
50 x Sample widget 3 @ $10 ea.
We're using the
$number
formatter here to format the amount
property value. Last modified 1yr ago