Functions
Functions allow you to manipulate data in your template
Last updated
Functions allow you to manipulate data in your template
Last updated
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 |
---|---|---|---|
This function does not have a return value.
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 in the template where they are declared.
Add two numbers together
{{$add number1 number2 [format]}}
Returns the total.
Example
Subtracts the second number from the first number.
{{$subtract number1 number2 [format]}}
Returns the total.
Example
Multiplies two numbers together.
{{$multiply number1 number2 [format]}}
Returns the product.
Example
Divides the first number by the second number.
{{$divide dividend divisor [format]}}
Returns the total.
Example
Computes the sum of the values.
This function has multiple signatures
Computes the minimum number in an array.
{{$min array [format]}}
Returns the minimum value.
Example
Computes the maximum number in an array.
{{$max array [format]}}
Returns the maiximum value.
Example
Computes the average of all values in an array.
{{$mean array [format]}}
Returns the average value.
Example
Computes number
rounded to precision
.
{{$round number [precision=0] [format]}}
Returns the rounded value.
Example
Computes number
rounded down to precision
.
{{$floor number [precision=0] [format]}}
Returns the rounded down value.
Example
Computes number
rounded up to precision
.
{{$ceil number [precision=0] [format]}}
Returns the rounded-up value.
Example
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}}
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.
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.
Filters an array/list of items.
{{$filter array
path
operator
[value]}}
Video walk-through of the filter process
Group items together and create a loop of those items
Video walk-through of the group process
Concatenates an array (list) of items into a string.
{{$join array [path] [separator] [final] }}
Returns the extension name of a filename.
{{$extname filename }}
Displays the raw merge data used to create the document. Useful for debugging your template when merging documents.
{{$inspect [expandDepth=1]}}
Documentation coming soon!
Creates a link to a given URL
{{$link url [text]}}
Link to the given URL.
Example
Renders markdown content
{{$md content}}
Troubleshooting
Spaces at the end of content wrapped in tags such as ** will render the tags as raw text.
Example:
"Howdy, **Partner! **"
renders as **Howdy, Partner! **
"Howdy, **Partner!**" renders as Howdy,
Partner!
Name | Description | Type | Required |
---|---|---|---|
Name | Description | Type | Required |
---|---|---|---|
Name | Description | Type | Required |
---|---|---|---|
Name | Description | Type | Required |
---|---|---|---|
Name | Description | Type | Required |
---|---|---|---|
Name | Description | Type | Required |
---|---|---|---|
Name | Description | Type | Required |
---|---|---|---|
Name | Description | Type | Required |
---|---|---|---|
Name | Description | Type | Required |
---|---|---|---|
Name | Description | Type | Required |
---|---|---|---|
Name | Description | Type | Required |
---|---|---|---|
Name | Description | Type | Required |
---|---|---|---|
Name | Description | Type | Required |
---|---|---|---|
Name | Description | Type | Required |
---|---|---|---|
Name | Description | Type | Required |
---|---|---|---|
Name | Description | Type | Required |
---|---|---|---|
Name | Description | Type | Required |
---|---|---|---|
Name | Description | Type | Required |
---|---|---|---|
Name | Description | Type | Required |
---|---|---|---|
Name | Description | Type | Required |
---|---|---|---|