Functions
Functions allow you to manipulate data in your template
Documint uses an enhanced version of Handlebars as its templating engine. This means all valid Handlebars syntax is valid Documint syntax. Below is a list of custom functions that can be used in your Documint templates.
You can combine functions by wrapping the inner function in parenthesis.
Example:
{{$link ($get "path.to.website_url") "Go to website"}}
Here we're using the
$get
function within the $link
function by wrapping it inside of parenthesis.Creates a custom variable in your template which you can access from other parts of your template
{{$var name value}}
Name | Description | Type | Required |
---|---|---|---|
name | The name of the variable. This will be used to access it later. Must be a valid JavaScript key | String | |
value | The value of the variable | Any |
This function does not have a return value.
Template
Result
{{$var "custom_var" "Custom value"}}
...
{{custom_var}} // Used somewhere else in the template after the above declaration
Custom value
Template
Data
Result
Create a custom variable and set the value to the results of the filter function where we filter items that have a quantity of 10 or more.

Repeat the section for each item in the custom variable
​

{
"items":[
{
"name": "Item #1",
"qty": 5
},
{
"name": "Item #2",
"qty": 10
},
{
"name": "Item #3",
"qty": 15
},
{
"name": "Item #4",
"qty": 20
}
]
}

Variables can only be accessed after the point in the template where they are declared.
Add two numbers together
{{$add number1 number2 [format]}}
Name | Description | Type | Required |
---|---|---|---|
number1 | The first number in an addition. | Number | |
number2 | The second number in an addition. | Number | |
format | String |
Returns the total.
Example
Template
Data
Result
{{$add subtotal tax}}
{
"subtotal":100,
"tax": 7.50
}
107.5
Subtracts the second number from the first number.
{{$subtract number1 number2 [format]}}
Name | Description | Type | Required |
---|---|---|---|
number1 | The first number in a subtraction. | Number | |
number2 | The second number in a subtraction. | Number | |
format | String |
Returns the total.
Example
Template
Data
Result
{{$subtract subtotal discount}}
{
"subtotal":100,
"discount": 21.5
}
78.5
Multiplies two numbers together.
{{$multiply number1 number2 [format]}}
Name | Description | Type | Required |
---|---|---|---|
number1 | The first number in a multiplication. | Number | |
number2 | The second number in a multiplication. | Number | |
format | String |
Returns the product.
Example
Template
Data
Result
{{$multiply subtotal .075}}
{
"subtotal": 150
}
11.25
Divides the first number by the second number.
{{$divide dividend divisor [format]}}
Name | Description | Type | Required |
---|---|---|---|
dividend | The first number in a division. | Number | |
divisor | The second number in a division. | Number | |
format | String |
Returns the total.
Example
Template
Data
Result
{{$divide wins total_games}}
{
"wins": 3,
"total_games": 15
}
.2
Computes the sum of the values.
This function has multiple signatures
Signature 1
Signature 2
Signature 3
{{$sum array [format]}}
​
​
Name | Description | Type | Required |
---|---|---|---|
array | List of numbers to sum. | Number Array | |
format | String |
​
Example
Template
Data
Result
{{$sum hours_worked}}
{
"hours_worked": [3, 6, 4, 12]
}
25
Returns the total.
{{$sum number1 number2 [...] [format]}}
​
Computes the sum of numbers passed as arguments.
​
Name | Description | Type | Required |
---|---|---|---|
number1 | The first number to sum. | Number | |
number2 | The second number to sum. | Number | |
[...] | The remaining numbers to sum. | Number | |
format | String |
​
Example
Template
Data
Result
{{$sum subtotal discount tax}}
{
"subtotal": 150,
"discount": -20,
"tax": 6.50
}
136.5
Returns the total.
{{$sum collection path [format]}}
​
​
Name | Description | Type | Required |
---|---|---|---|
collection | An array of objects | Collection | |
path | Path to the number property on each object. | String | |
format | String |
​
Example
Template
Data
Result
{{$sum items "price"}}
{
"items": [
{ "name":"Rocket Skates", "price":160.3 },
{ "name":"Acme Glue", "price":15.6 },
{ "name":"Wing Suit", "price":699.99 },
]
}
875.89
Returns the total.
Computes the minimum number in an array.
{{$min array [format]}}
Name | Description | Type | Required |
---|---|---|---|
array | Array of numbers. | Number Array | |
format | String |
Returns the minimum value.
Example
Template
Data
Result
{{$min scores}}
{
"scores": [ 3, 22, 9, 15 ]
}
3
Computes the maximum number in an array.
{{$max array [format]}}
Name | Description | Type | Required |
---|---|---|---|
array | Array of numbers. | Number Array | |
format | String |
Returns the maiximum value.
Example
Template
Data
Result
{{$max scores}}
{
"scores": [ 3, 22, 9, 15 ]
}
22
Computes the average of all values in an array.
{{$mean array [format]}}
Name | Description | Type | Required |
---|---|---|---|
array | Array of numbers. | Number Array | |
format | String |
Returns the average value.
Example
Template
Data
Result
{{$mean scores}}
{
"scores": [ 3, 22, 9, 15 ]
}
12.25
Computes
number
rounded to precision
.{{$round number [precision=0] [format]}}
Name | Description | Type | Required |
---|---|---|---|
number | Array of numbers. | Number | |
precision | Decimal precision to round to. Default=0 | Number | |
format | String |
Returns the rounded value.
Example
Template
Data
Result
{{$round avg_age}}
{
"avg_age": 39.486
}
39
Computes
number
rounded down to precision
.{{$floor number [precision=0] [format]}}
Name | Description | Type | Required |
---|---|---|---|
number | Array of numbers. | Number | |
precision | Decimal precision to round down to. Default=0 | Number | |
format | String |
Returns the rounded down value.
Example
Template
Data
Result
{{$floor avg_age}}
{
"avg_age": 39.682
}
39
Computes
number
rounded up to precision
.{{$ceil number [precision=0] [format]}}
Name | Description | Type | Required |
---|---|---|---|
number | Array of numbers. | Number | |
precision | Decimal precision to round down to. Default=0 | Number | |
format | String |
Returns the rounded-up value.
Example
Template
Data
Result
{{$ceil avg_age}}
{
"avg_age": 39.182
}
40
Loops over an array (list) of items. This is different than the other functions because it has an opening (
{{#each}}
) and closing ({{/each}}
) tag and uses an #
instead of a $
to prefix the function name. The content within the opening and closing tags is set to the context of the current item in the loop. This means that any variables used within the opening and closing tags are relative to the current item in the loop. If the list of items being looped over is a list of objects, then variable names will represent properties on that object. See example below.{{#each array }}{{this}}{{/each}}
Name | Description | Type | Required |
---|---|---|---|
array | List of items to repeat/loop over | String Array Number Array Boolean Array Object Array Array Array |
Content within the opening and closing tags, for each item in the given array/list.
In this example we're looping over an array/list of Objects. We can access the properties of the current object in the loop simply by using the name of the property. In the case below, we're displaying the
name
property of each object using the {{name}}
token. This works because the within the opening and closing tags of the #each
function, the context is set to the current item in the loop. Template
Data
Result
{{#each characters}}{{name}}, {{/each}}
{
"characters": [
{ "name": "Wile E. Coyote", "email":"[email protected]" },
{ "name": "Road Runer", "email":"[email protected]" }
]
}
Wile E. Coyote, Road Runner
In this example, we're looping over an array/list of Strings. We use the
this
keyword to reference the current item in the loop. this
always represents the current item in the loop, even when looping over data types other than Strings.Template
Data
Result
{{#each characters}}{{this}}, {{/each}}
{
"characters": [ "Wile E. Coyote", "Road Runer" ]
}
Wile E. Coyote, Road Runner
Filters an array/list of items.
Name | Description | Type | Required |
---|---|---|---|
array | String String Array Number Array Object Array | ||
Path to property if looping over an array/list of Objects. | String | ||
The operator used to evaluate each item in the array/list. Note: If looping over an array/list of Strings, Numbers or Booleans then this should be the value to check against. | String | ||
value | The value to compare variable's value to. Required when using an operator that requries two arguments. | String Number Boolean |
Template
Data
Result
{{$filter products "category" "isIn" "Disguise,Explosive"}}
{
"products": [
{ "name":"Batman Costume", "category":"Disguise" },
{ "name":"TNT", "category":"Explosive" },
{ "name":"Jet-Propelled Unicycle", "category":"Transportation" }
]
}
[
{ "name":"Batman Costume", "category":"Disguise" },
{ "name":"TNT", "category":"Explosive" }
]
Documentation coming soon.
Concatenates an array (list) of items into a string.
{{$join array [path] [separator] [final] }}
Name | Description | Type | Required |
---|---|---|---|
array | String String Array Number Array Object Array | ||
path | If the array is a collection (an array of objects) then use this path to specify which property in the object should be concatenated. Default value: ", " | String | |
separator | String that separates each item in the array. | String | |
final | The string that's used to separate the last two items. | String |
Template
Data
Result
{{$join categories ", " " & "}}
{
"categories": ["Disguise", "Explosive", "Transportation"]
}
Disguise, Maintenance & Transportation