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

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

{{$get "customer.company_name"}}
{{$get "customer.contacts[0].name"}}
{{$get "customer.contacts[1].email"}}
{{$get "customer.address.country" "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

Returns

This function does not have a return value.

Example #1 - Basic

{{$var "custom_var" "Custom value"}}
...
{{custom_var}} // Used somewhere else in the template after the above declaration

Example #2 - Advanced

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

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

Returns

Link to the given URL.

Example

{{$link company.website}}
{{$link company.website company.name}}

$md

Renders markdown content

Signature

{{$md content}}

Arguments

Example

{{$md notes}}

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

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.

{{#each characters}}{{name}}, {{/each}}

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.

{{#each characters}}{{this}}, {{/each}}

$filter

Filters an array/list of items.

Signature

{{$filter array pathoperator [value]}}

Arguments

Example - Array of Objects

{{$filter products "category" "isIn" "Disguise,Explosive"}}

$group

Documentation coming soon.

$join

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

Signature

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

Arguments

Example #1 - Array of strings

{{$join categories ", " " & "}}

Example #2- Collection (array of objects)

{{$join items "name" ", " " & "}}

Example #3 - Path to array

{{$join "company.employees" "name" ", " " & "}}

Helpers

$extname

Returns the extension name of a filename.

Signature

{{$extname filename }}

Arguments

Example

{{$extname filename}}

$inspect

Documentation coming soon..

Last updated