Help Center
Go to siteOpen app
  • Help Center
  • Welcome to the Help Center!
  • Guides
    • Designing a Basic Template from Scratch
    • Adding Variables
    • e-signatures with SignNow
    • How to create Tables
  • Templates
    • What's a template?
    • Page Elements
      • Layout Elements
      • Content Elements
      • Conditional Logic
      • Repeating Elements
    • Settings
    • Headers & Footers
    • Data and Variables
      • Syntax
      • Data Types
      • Formatting
      • Functions
        • $calc (beta)
      • Operators
    • Template Designer v2 (Beta)
      • Connections
        • Airtable Connection
        • HubSpot (Coming Soon)
      • Fields Editor
      • Tokens
      • Coming soon
  • Documents
    • What is a Document?
    • Minted Documents
  • Additional Resources
    • How-To Videos
      • Formatting Variables
      • Airtable Integrations
      • Airtable Data and Variables Videos
      • How to add variable images from your Airtable attachments
      • How to filter items in your Documents
      • How to group items in your Documents
      • Signing Documents with SignNow and Zapier
      • Add charts to your Documents with QuickChart.io
      • Add a Word Cloud chart to your Documents with QuickChart.io
      • Using Make.com (Integromat) to create line items in your documents
      • How to QR codes to your documents with QuickChart.io
      • How to add a progress chart to your documents with QuickChart.io
      • How to connect your Documint account using API keys
      • How to connect your Documint account to Airtable using your Personal Access Token (PAT)
    • Glossary
    • Frequently Asked Questions
    • Troubleshooting
  • Integrations
    • HubSpot
      • Installing the Documint app
      • Connecting your Documint account
      • Navigating the Documint App
      • Working with Custom Object Data
      • Adding HubSpot Properties to Your Template
      • Generating Your documents
      • Using Quick-Create
      • Using Workflows to Create Your Documents
      • Troubleshooting the Documint App
      • Uninstalling the Documint App
    • Airtable
      • Add your Airtable Personal Access Token
      • Airtable Extension
      • Generation Link
      • Automation Script
      • Field Types to Documint Variables
      • Adding Images from Airtable
      • Expanding Linked Records
      • Lookup Fields
      • Documents from Multiple Records
      • Duplicate Document Prevention
      • Password Protection
      • Creating Documents
        • Preview Mode
    • Zapier
    • Make.com
    • Coda
    • Stacker
    • Noloco
    • Softr
    • Pory
    • REST API
Powered by GitBook
On this page
  • General
  • $calc (beta)
  • $var
  • Math
  • $add
  • $subtract
  • $multiply
  • $divide
  • $sum
  • $min
  • $max
  • $mean
  • $round
  • $floor
  • $ceil
  • List/Arrays
  • #each
  • $filter
  • $group
  • $join
  • Helpers
  • $extname
  • $inspect
  • Content
  • $iframe
  • $link
  • $md

Was this helpful?

  1. Templates
  2. Data and Variables

Functions

Functions allow you to manipulate data in your template

PreviousFormattingNext$calc (beta)

Last updated 2 months ago

Was this helpful?

Documint uses an enhanced version of 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.

$var

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

Note:

Variables must be added to templates before (higher up in the template) they are used.

Examples

Good: {{$var "tax_rate" 0.07}} //Variable is declared before it is used

Tax Rate: {{$number tax_rate "0%"}}

Bad:

Tax Rate: {{$number tax_rate "0%"}}

{{$var "tax_rate" 0.07}} //Variable is declared after it is used

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

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

Custom value

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

{
  "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.

Math

$add

Add two numbers together

Signature

{{$add number1 number2 [format]}}

Arguments

Name
Description
Type
Required

number1

The first number in an addition.

Number

number2

The second number in an addition.

Number

format

String

Returns

Returns the total.

Example

{{$add subtotal tax}}
{
    "subtotal":100,
    "tax": 7.50
}

107.5

$subtract

Subtracts the second number from the first number.

Signature

{{$subtract number1 number2 [format]}}

Arguments

Name
Description
Type
Required

number1

The first number in a subtraction.

Number

number2

The second number in a subtraction.

Number

format

String

Returns

Returns the total.

Example

{{$subtract subtotal discount}}
{
    "subtotal":100,
    "discount": 21.5
}

78.5

$multiply

Multiplies two numbers together.

Signature

{{$multiply number1 number2 [format]}}

Arguments

Name
Description
Type
Required

number1

The first number in a multiplication.

Number

number2

The second number in a multiplication.

Number

format

String

Returns

Returns the product.

Example

{{$multiply subtotal .075}}
{
    "subtotal": 150
}

11.25

$divide

Divides the first number by the second number.

Signature

{{$divide dividend divisor [format]}}

Arguments

Name
Description
Type
Required

dividend

The first number in a division.

Number

divisor

The second number in a division.

Number

format

String

Returns

Returns the total.

Example

{{$divide wins total_games}}
{
    "wins": 3,
    "total_games": 15
}

.2

$sum

Computes the sum of the values.

This function has multiple signatures

{{$sum array [format]}}

Computes the sum of numbers in an array.

Arguments

Name
Description
Type
Required

array

List of numbers to sum.

Number Array

format

String

Example

{{$sum hours_worked}}
{
    "hours_worked": [3, 6, 4, 12]
}

25

Returns

Returns the total.

{{$sum number1 number2 [...] [format]}}

Computes the sum of numbers passed as arguments.

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

{{$sum subtotal discount tax}}
{
    "subtotal": 150,
    "discount": -20,
    "tax": 6.50
}

136.5

Returns

Returns the total.

{{$sum collection path [format]}}

Computes the sum of numbers within a collection (an array of objects).

Arguments

Name
Description
Type
Required

collection

An array of objects

Collection

path

Path to the number property on each object.

String

format

String

Example

{{$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

Returns the total.

$min

Computes the minimum number in an array.

Signature

{{$min array [format]}}

Arguments

Name
Description
Type
Required

array

Array of numbers.

Number Array

format

String

Returns

Returns the minimum value.

Example

{{$min scores}}
{
    "scores": [ 3, 22, 9, 15 ]
}

3

$max

Computes the maximum number in an array.

Signature

{{$max array [format]}}

Arguments

Name
Description
Type
Required

array

Array of numbers.

Number Array

format

String

Returns

Returns the maiximum value.

Example

{{$max scores}}
{
    "scores": [ 3, 22, 9, 15 ]
}

22

$mean

Computes the average of all values in an array.

Signature

{{$mean array [format]}}

Arguments

Name
Description
Type
Required

array

Array of numbers.

Number Array

format

String

Returns

Returns the average value.

Example

{{$mean scores}}
{
    "scores": [ 3, 22, 9, 15 ]
}

12.25

$round

Computes number rounded to precision.

Signature

{{$round number [precision=0] [format]}}

Arguments

Name
Description
Type
Required

number

Array of numbers.

Number

precision

Decimal precision to round to. Default=0

Number

format

String

Returns

Returns the rounded value.

Example

{{$round avg_age}}
{
    "avg_age": 39.486
}

39

$floor

Computes number rounded down to precision.

Signature

{{$floor number [precision=0] [format]}}

Arguments

Name
Description
Type
Required

number

Array of numbers.

Number

precision

Decimal precision to round down to.

Default=0

Number

format

String

Returns

Returns the rounded down value.

Example

{{$floor avg_age}}
{
    "avg_age": 39.682
}

39

$ceil

Computes number rounded up to precision.

Signature

{{$ceil number [precision=0] [format]}}

Arguments

Name
Description
Type
Required

number

Array of numbers.

Number

precision

Decimal precision to round down to.

Default=0

Number

format

String

Returns

Returns the rounded-up value.

Example

{{$ceil avg_age}}
{
    "avg_age": 39.182
}

40

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 ArrayNumber ArrayBoolean ArrayObject ArrayArray 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.

{{#each characters}}{{name}}, {{/each}}
{
    "characters": [
        { "name": "Wile E. Coyote", "email":"wile.coyote@acme.co" },
        { "name": "Road Runer",     "email":"road.runner@acme.co" }
    ]
}

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.

{{#each characters}}{{this}}, {{/each}}
{
    "characters": [ "Wile E. Coyote", "Road Runer" ]
}

Wile E. Coyote, Road Runner

$filter

Filters an array/list of items.

Signature

{{$filter array pathoperator [value]}}

Arguments

Name
Description
Type
Required

array

StringString ArrayNumber ArrayObject 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.

StringNumberBoolean

Example - Array of Objects

{{$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" }
]

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

Name
Description
Type
Required

array

StringString ArrayNumber ArrayObject Array

path

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

{{$join categories ", " " & "}}
{
  "categories": ["Disguise", "Explosive", "Transportation"]
}

Disguise, Maintenance & Transportation

Example #2- Collection (array of objects)

{{$join items "name" ", " " & "}}
{
  "items": [
    { "name": "Glue V1", "price": 9.99 },
    { "name": "Artificial Rock", "price": 26.99 },
    { "name": "Bat-Man's Outfit", "price": 159.99 }
  ]
}

Glue V1, Artificial Rock & Bat-Man's Outfit

Example #3 - Path to array

{{$join "company.employees" "name" ", " " & "}}
{
  "company": {
    "name": "Acme Co.",
    "employees": [
      {
        "name": "Bernadine Burton",
        "role": "Decoy"
      },
      {
        "name": "Good Battle",
        "role": "Field Agent"
      },
      {
        "name": "Dennis Miles",
        "role": "Field Agent"
      }
    ]
  }
}

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

{{$extname filename}}
{
  "filename": "https://acmec.co/assets/image.jpg"
}

jpg

$inspect

Displays the raw merge data used to create the document. Useful for debugging your template when merging documents.

Signature

{{$inspect [expandDepth=1]}}

Arguments

Name
Description
Type
Required

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]

StringNumber

Example

{{$inspect 2}}
{
    "name":"Order 2321",
    "account":[
        {
            "name":"Acme Co.",
            "address":{
                "street": "123 Main St.",
                "city": "New York",
                "state": "New York"
            }
        }
    ],
    "items":[
        { "name":"Widget 1", "price":123, "qty": 1, "amount": 123 },
        { "name":"Widget 2", "price":321, "qty": 1, "amount": 321 },
        { "name":"Widget 3", "price": 456, "qty": 1, "amount": 456 },
    ]
}

Content

$iframe

Documentation coming soon!

$link

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

{{$link company.website}}
{{$link company.website company.name}}
{
    "company":{
        "name":"Acme Co.",
        "website":"https://www.acme.co"
    }
}

$md

Renders markdown content

Signature

{{$md content}}

Arguments

Name
Description
Type
Required

content

Markdown content

String

Example

{{$md notes}}
{
    "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"
}

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!

used to format the result

used to format the result

used to format the result

used to format the result

used to format the result

used to format the result

used to format the result

used to format the result

used to format the result

used to format the result

used to format the result

used to format the result

used to format the result

Accepts either an array of data or a relative , as a String, to an array.

Note: If looping over a list of Strings, Numbers or Booleans then this should be the .

Accepts either an array of data or a relative , as a String, to an array.

If the array is a collection (an array of objects) then use this to specify which property in the object should be concatenated.

Handlebars
$calc (beta)
https://www.acme.co
Acme Co.
Format string
Format string
Format string
Format string
Format string
Format string
Format string
Format string
Format string
Format string
Format string
Format string
Format string
path
path
operator
operator
path
path