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

Strings are simply text data.

Example

{{customer_name}}

Numbers

Numbers are integers or floating-point decimals.

Example

{{total_amount}}

You can format numbers using the $number format.

Booleans

Booleans are values that are either true or false . They can not contain any values other than these.

Example

{{is_fragile}}

Objects

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].

Example

{{address.street1}}

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.

Arrays

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.

Example 1: Display a single item

{{movies[0]}}

{{movies[2]}}

Example 2: Display all items

{{#each movies }} Movie: {{this}} {{/each}}

You can also repeat an element for each item in an array. To learn more check out Repeating Elements

[object Object] Error

Similar 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.

Collections

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.

{{#each line_items}} {{qty}} x {{name}} @ {{$number amount "$0,0.00"}} ea. {{/each}}

We're using the $number formatter here to format the amount property value.

Last updated