Data Types

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.

String

Strings are simply text data.

Example:

Number

Numbers are integers or floating-point decimals.

Example:

Boolean

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

Example:

Object

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:

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.

Array

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:

To set up our template we will first need to select an element to repeat. In this example, we are going to repeat the Text element. This is done by selecting the Text element,

clicking "Add/Edit Logic" at the top of the Properties panel,

switching to the "Repeat/Loop" tab then entering movies into the "List variable" field.

To display the current item in the array we will add a variable called {{ this }} to our text element.

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 looped over to display each item in the array and display the current item using the {{ this }} variable.

Collection

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 create a table using a section for the row (this will be repeated for each item in the collection) and columns as cells to contain the properties of each order line item.

We'll start by adding a section to our template

We will select the entire section itself, then open the Logic editor by clicking "Add/Edit Logic" at the top of the properties panel.

We'll switch to the "Repeat/loop" tab then enter order_line_items in the "List variable" field and click "Save".

We'll add a Text element to the first column in our section then add the variable token {{ name }}.

Because we are repeating the section for each item in the order_line_items collection, any variable added within that section will be in the context of the current order line item object being rendered. So, when we add a variable like {{ name }} within the section, we are telling Documint to display the value of the name property of the current order line item.

Next, we'll clone the first column three times, delete the empty column and replace {{ name }} in the three new columns with {{ price }}, {{ quantity }} and {{ amount }} respectively.

If we wanted to we could format price, quantity, and amount variables using the number formatter but that is outside the scope of this guide.

Last updated