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.
Combining Functions
You can combine functions by wrapping the inner function in parenthesis.
//Example
{{$multiply ($add amount_1 amount_2) ($add amount_3 amount_4)}}
Here we're using the $add
function to sum two sets of values then multiplying them together. Functions in parenthesis will be evaluated first and returned to its parent function.
General
$calc (beta)
The $calc function is a powerful expression evaluator that enables complex calculations, string manipulations, array operations, and provides a secure sandbox environment within your templates.
$calc$var
Creates a custom variable in your template which you can access from other parts of your template
Signature
{{$var name value}}
Arguments
name
The name of the variable. This will be used to access it later. Must be a valid JavaScript key
value
The value of the variable
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

Math
$add
Add two numbers together
Signature
{{$add number1 number2 [format]}}
Arguments
number1
The first number in an addition.
number2
The second number in an addition.
format
Format string used to format the result
Returns
Returns the total.
Example
{{$add subtotal tax}}
$subtract
Subtracts the second number from the first number.
Signature
{{$subtract number1 number2 [format]}}
Arguments
number1
The first number in a subtraction.
number2
The second number in a subtraction.
format
Format string used to format the result
Returns
Returns the total.
Example
{{$subtract subtotal discount}}
$multiply
Multiplies two numbers together.
Signature
{{$multiply number1 number2 [format]}}
Arguments
number1
The first number in a multiplication.
number2
The second number in a multiplication.
format
Format string used to format the result
Returns
Returns the product.
Example
{{$multiply subtotal .075}}
$divide
Divides the first number by the second number.
Signature
{{$divide dividend divisor [format]}}
Arguments
dividend
The first number in a division.
divisor
The second number in a division.
format
Format string used to format the result
Returns
Returns the total.
Example
{{$divide wins total_games}}
$sum
Computes the sum of the values.
$min
Computes the minimum number in an array.
Signature
{{$min array [format]}}
Arguments
array
Array of numbers.
format
Format string used to format the result
Returns
Returns the minimum value.
Example
{{$min scores}}
$max
Computes the maximum number in an array.
Signature
{{$max array [format]}}
Arguments
array
Array of numbers.
format
Format string used to format the result
Returns
Returns the maiximum value.
Example
{{$max scores}}
$mean
Computes the average of all values in an array.
Signature
{{$mean array [format]}}
Arguments
array
Array of numbers.
format
Format string used to format the result
Returns
Returns the average value.
Example
{{$mean scores}}
$round
Computes number
rounded to precision
.
Signature
{{$round number [precision=0] [format]}}
Arguments
number
Array of numbers.
precision
Decimal precision to round to. Default=0
format
Format string used to format the result
Returns
Returns the rounded value.
Example
{{$round avg_age}}
$floor
Computes number
rounded down to precision
.
Signature
{{$floor number [precision=0] [format]}}
Arguments
number
Array of numbers.
precision
Decimal precision to round down to.
Default=0
format
Format string used to format the result
Returns
Returns the rounded down value.
Example
{{$floor avg_age}}
$ceil
Computes number
rounded up to precision
.
Signature
{{$ceil number [precision=0] [format]}}
Arguments
number
Array of numbers.
precision
Decimal precision to round down to.
Default=0
format
Format string used to format the result
Returns
Returns the rounded-up value.
Example
{{$ceil avg_age}}
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
array
List of items to repeat/loop over
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
path
operator
[value]}}
Arguments
array
Accepts either an array of data or a relative path, as a String, to an 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.
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.
value
The value to compare variable's value to. Required when using an operator that requries two arguments.
Example - Array of Objects
{{$filter products "category" "isIn" "Disguise,Explosive"}}
Video walk-through of the filter process
$group
Group items together and create a loop of those items
Video walk-through of the group process
$join
Concatenates an array (list) of items into a string.
Signature
{{$join array [path] [separator] [final] }}
Arguments
array
Accepts either an array of data or a relative path, as a String, to an 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: ", "
separator
String that separates each item in the array.
final
The string that's used to separate the last two items.
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
filename
The name of the file that you're trying to get the extension name of.
Example
{{$extname filename}}
$inspect
Displays the raw merge data used to create the document. Useful for debugging your template when merging documents.
Signature
{{$inspect [expandDepth=1]}}
Arguments
expandDepth
The number of levels deep to expand nested objects and arrays. Unexpaded objects will will display as [object Object] and unexpected arrays will display as [array Object]
Example
{{$inspect 2}}
Content
$iframe
Documentation coming soon!
$link
Creates a link to a given URL
Signature
{{$link url [text]}}
Arguments
url
URL value of the link
text
Text to display in document. If no value is provided the URL of the link will be displayed
Returns
Link to the given URL.
Example
{{$link company.website}}
{{$link company.website company.name}}
$md
Renders markdown content
Signature
{{$md content}}
Arguments
content
Markdown content
Example
{{$md notes}}
Last updated
Was this helpful?