Functions
Functions add functionality to 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.

Combining Functions

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.

General

$get

Returns the value of the given path.

Signature

{{$get path [defaultValue] [global=true|false]}}

Arguments

Name
Description
Type
Required
path
The path to value you are trying to display.
String
defaultValue
Value that is displayed if no value is found at the given path.
Number
String
global
If true, the given path will be relative to the global context. If false, the path will be relative to the current context. For example, if you are using the this function within a loop, the context will be the current item in the loop. If global is set to true, then the context will be set to the root of your data.
Boolean

Returns

The value at the given path or, if there is no value at the path and a default value is provided, the default value will be returned.

Example

Template
Data
Result
1
{{$get "customer.company_name"}}
2
{{$get "customer.contacts[0].name"}}
3
{{$get "customer.contacts[1].email"}}
4
{{$get "customer.address.country" "United States"}}
Copied!
1
{
2
"order_number": "O-0012",
3
"customer": {
4
"company_name": "Acme Co.",
5
"address":{
6
"street":"123 Main St.",
7
"city": "New York",
8
"state":"New York"
9
},
10
"contacts":[
11
{
12
"name":"Wile E. Coyote",
13
14
},
15
{
16
"name":"Road Runner",
17
18
}
19
]
20
}
21
}
Copied!
Acme Co.
Wile E. Coyote
United States
To access a specific item in an array/list, add the position of the item in square brackets [] like so: [0]. Indices are zero-based which means the first item in the array/list is at position 0, the second item is at position 1 and so on.
This method always accesses data from its current context. For example, if it's used within a loop, then the context of the path is set to the current item in the loop.

$var

Creates a custom variable in your template which you can access from other parts of your template

Signature

{{$var name value}}

Arguments

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

Returns

This function does not have a return value.

Example #1 - Basic

Template
Result
1
{{$var "custom_var" "Custom value"}}
2
...
3
{{custom_var}} // Used somewhere else in the template after the above declaration
Copied!
Custom value

Example #2 - Advanced

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
1
{
2
"items":[
3
{
4
"name": "Item #1",
5
"qty": 5
6
},
7
{
8
"name": "Item #2",
9
"qty": 10
10
},
11
{
12
"name": "Item #3",
13
"qty": 15
14
},
15
{
16
"name": "Item #4",
17
"qty": 20
18
}
19
]
20
}
Copied!
Variables can only be accessed after the point where they've been declared.

Content

$iframe

Documentation coming soon!
Creates a link to a given URL

Signature

{{$link url [text]}}

Arguments

Name
Description
Type
Required
url
URL value of the link
String
text
Text to display in document. If no value is provided the URL of the link will be displayed
String

Returns

Link to the given URL.
Example
Template
Data
Result
1
{{$link company.website}}
2
{{$link company.website company.name}}
Copied!
1
{
2
"company":{
3
"name":"Acme Co.",
4
"website":"https://www.acme.co"
5
}
6
}
Copied!

$md

Renders markdown content

Signature

{{$md content}}

Arguments

Name
Description
Type
Required
content
Markdown content
String

Example

Template
Data
Result
1
{{$md notes}}
Copied!
1
{
2
"notes":"Before moving forward you need to complete the following items:\n[ ] Checklist item one\n[x] Checklist item two\n[ ] Checklist item three\n"
3
}
Copied!

List/Arrays

#each

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.

Signature

{{#each array }}{{this}}{{/each}}

Arguments

Name
Description
Type
Required
array
List of items to repeat/loop over
String Array
Number Array
Boolean Array
Object Array
Array Array

Returns

Content within the opening and closing tags, for each item in the given array/list.

Example - Array of Objects

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
1
{{#each characters}}{{name}}, {{/each}}
Copied!
1
{
2
"characters": [
3
{ "name": "Wile E. Coyote", "email":"[email protected]" },
4
{ "name": "Road Runer", "email":"[email protected]" }
5
]
6
}
Copied!
Wile E. Coyote, Road Runner

Example - Array of Strings

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
1
{{#each characters}}{{this}}, {{/each}}
Copied!
1
{
2
"characters": [ "Wile E. Coyote", "Road Runer" ]
3
}
Copied!
Wile E. Coyote, Road Runner

$filter

Filters an array/list of items.

Signature

{{$filter array pathoperator [value]}}

Arguments

Name
Description
Type
Required
array
Accepts either an array of data or a relative path, as a String, to an array.
String
String Array
Number Array
Object Array
path
Path to property if looping over an array/list of Objects.
Note: If looping over a list of Strings, Numbers or Booleans then this should be the operator.
String
operator
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

Example - Array of Objects

Template
Data
Result
1
{{$filter products "category" "isIn" "Disguise,Explosive"}}
Copied!
1
{
2
"products": [
3
{ "name":"Batman Costume", "category":"Disguise" },
4
{ "name":"TNT", "category":"Explosive" },
5
{ "name":"Jet-Propelled Unicycle", "category":"Transportation" }
6
]
7
}
Copied!
1
[
2
{ "name":"Batman Costume", "category":"Disguise" },
3
{ "name":"TNT", "category":"Explosive" }
4
]
Copied!

$group

Documentation coming soon.

$join

Concatenates an array (list) of items into a string.

Signature

{{$join array [path] [separator] [final] }}

Arguments

Name
Description
Type
Required
array
Accepts either an array of data or a relative path, as a String, to an 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

Example #1 - Array of strings

Template
Data
Result
1
{{$join categories ", " " & "}}
Copied!
1
{
2
"categories": ["Disguise", "Explosive", "Transportation"]
3
}
Copied!
Disguise, Maintenance & Transportation

Example #2- Collection (array of objects)

Template
Data
Result
1
{{$join items "name" ", " " & "}}
Copied!
1
{
2
"items": [
3
{ "name": "Glue V1", "price": 9.99 },
4
{ "name": "Artificial Rock", "price": 26.99 },
5
{ "name": "Bat-Man's Outfit", "price": 159.99 }
6
]
7
}
Copied!
Glue V1, Artificial Rock & Bat-Man's Outfit

Example #3 - Path to array

Template
Data
Result
1
{{$join "company.employees" "name" ", " " & "}}
Copied!
1
{
2
"company": {
3
"name": "Acme Co.",
4
"employees": [
5
{
6
"name": "Bernadine Burton",
7
"role": "Decoy"
8
},
9
{
10
"name": "Good Battle",
11
"role": "Field Agent"
12
},
13
{
14
"name": "Dennis Miles",
15
"role": "Field Agent"
16
}
17
]
18
}
19
}
Copied!
Bernadine Burton, Good Battle & Dennis Miles

Helpers

$extname

Returns the extension name of a filename.

Signature

{{$extname filename }}

Arguments

Name
Description
Type
Required
filename
The name of the file that you're trying to get the extension name of.
String

Example

Template
Data
Result
1
{{$extname filename}}
Copied!
1
{
2
"filename": "https://acmec.co/assets/image.jpg"
3
}
Copied!
jpg

$inspect

Documentation coming soon..
Last modified 14d ago