# Functions

Documint uses an enhanced version of [Handlebars](https://handlebarsjs.com/guide/#what-is-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.&#x20;

#### Combining Functions

You can combine functions by wrapping the inner function in parenthesis.

```handlebars
//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.&#x20;

## General

### $calc

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.

{% content-ref url="/pages/jzOYDrwNo79Vip129bQJ" %}
[$calc](/legacy-documentation/data-and-variables/functions/calc.md)
{% endcontent-ref %}

### $var <a href="#var" id="var"></a>

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

{% hint style="info" %}
**Note:**&#x20;

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

Examples

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

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

**Bad:**&#x20;

`Tax Rate: {{$number tax_rate "0%"}}`&#x20;

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

#### Signature

`{{$var name value}}`

#### Arguments

<table><thead><tr><th width="150">Name</th><th width="235.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>name</td><td>The name of the variable. This will be used to access it later. Must be a valid JavaScript key</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>true</td></tr><tr><td>value</td><td>The value of the variable</td><td><span data-option="3c1342f6b38a46e39064bd88015df50d">Any</span></td><td>true</td></tr></tbody></table>

#### Returns

This function does not have a return value.

#### **Example #1 - Basic**

{% tabs %}
{% tab title="Template" %}

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

{% endtab %}

{% tab title="Result" %}
Custom value
{% endtab %}
{% endtabs %}

#### Example #2 - Advanced

{% tabs %}
{% tab title="Template" %}
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.

![](/files/uTco9ajUqGpGZ0vltaIm)

Repeat the section for each item in the custom variable

![](/files/cZFkrr7R50huT4a3IVm9)
{% endtab %}

{% tab title="Data" %}

```
{
  "items":[
    {
      "name": "Item #1",
      "qty": 5
    },
    {
      "name": "Item #2",
      "qty": 10
    },
    {
      "name": "Item #3",
      "qty": 15
    },
    {
      "name": "Item #4",
      "qty": 20
    }
  ]
}
```

{% endtab %}

{% tab title="Result" %}
![](/files/3x5zIQztKIXZmMQr7QYq)
{% endtab %}
{% endtabs %}

{% hint style="info" %}
Variables can only be accessed after the point in the template where they are declared.
{% endhint %}

## Math

### $add <a href="#add" id="add"></a>

Add two numbers together

#### Signature

`{{$add number1 number2 [format]}}`

#### Arguments

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>number1</td><td>The first number in an addition.</td><td><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number</span></td><td>true</td></tr><tr><td>number2</td><td>The second number in an addition.</td><td><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number</span></td><td>true</td></tr><tr><td>format</td><td><a href="/pages/-M_x4dVDz1v6rNxxMMP9#standard">Format string</a> used to format the result</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>false</td></tr></tbody></table>

#### **Returns**

Returns the total.

**Example**

{% tabs %}
{% tab title="Template" %}

```javascript
{{$add subtotal tax}}
```

{% endtab %}

{% tab title="Data" %}

```json
{
    "subtotal":100,
    "tax": 7.50
}
```

{% endtab %}

{% tab title="Result" %}
107.5
{% endtab %}
{% endtabs %}

### $subtract <a href="#subtract" id="subtract"></a>

Subtracts the second number from the first number.

#### Signature

`{{$subtract number1 number2 [format]}}`

#### Arguments

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>number1</td><td>The first number in a subtraction.</td><td><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number</span></td><td>true</td></tr><tr><td>number2</td><td>The second number in a subtraction.</td><td><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number</span></td><td>true</td></tr><tr><td>format</td><td><a href="/pages/-M_x4dVDz1v6rNxxMMP9#standard">Format string</a> used to format the result</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>false</td></tr></tbody></table>

#### **Returns**

Returns the total.

**Example**

{% tabs %}
{% tab title="Template" %}

```javascript
{{$subtract subtotal discount}}
```

{% endtab %}

{% tab title="Data" %}

```json
{
    "subtotal":100,
    "discount": 21.5
}
```

{% endtab %}

{% tab title="Result" %}
78.5
{% endtab %}
{% endtabs %}

### $multiply <a href="#multiply" id="multiply"></a>

Multiplies two numbers together.

#### Signature

`{{$multiply number1 number2 [format]}}`

#### Arguments

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>number1</td><td>The first number in a multiplication.</td><td><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number</span></td><td>true</td></tr><tr><td>number2</td><td>The second number in a multiplication.</td><td><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number</span></td><td>true</td></tr><tr><td>format</td><td><a href="/pages/-M_x4dVDz1v6rNxxMMP9#standard">Format string</a> used to format the result</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>false</td></tr></tbody></table>

#### **Returns**

Returns the product.

**Example**

{% tabs %}
{% tab title="Template" %}

```javascript
{{$multiply subtotal .075}}
```

{% endtab %}

{% tab title="Data" %}

```json
{
    "subtotal": 150
}
```

{% endtab %}

{% tab title="Result" %}
11.25
{% endtab %}
{% endtabs %}

### $divide <a href="#divide" id="divide"></a>

Divides the first number by the second number.

#### Signature

`{{$divide dividend divisor [format]}}`

#### Arguments

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>dividend</td><td>The first number in a division.</td><td><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number</span></td><td>true</td></tr><tr><td>divisor</td><td>The second number in a division.</td><td><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number</span></td><td>true</td></tr><tr><td>format</td><td><a href="/pages/-M_x4dVDz1v6rNxxMMP9#standard">Format string</a> used to format the result</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>false</td></tr></tbody></table>

#### **Returns**

Returns the total.

**Example**

{% tabs %}
{% tab title="Template" %}

```javascript
{{$divide wins total_games}}
```

{% endtab %}

{% tab title="Data" %}

```json
{
    "wins": 3,
    "total_games": 15
}
```

{% endtab %}

{% tab title="Result" %}
.2
{% endtab %}
{% endtabs %}

### $sum <a href="#sum" id="sum"></a>

Computes the sum of the values.

{% hint style="info" %}
This function has multiple signatures
{% endhint %}

{% tabs %}
{% tab title="Signature 1" %}
`{{$sum array [format]}}`

Computes the sum of [numbers](broken://pages/-Mf-KWZIw6EzwOISMYUi#numbers) in an [array](broken://pages/-Mf-KWZIw6EzwOISMYUi#arrays).

#### Arguments&#x20;

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option><option value="749256e4cf85463181ee3afefe9c10b2" label="Number Array" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>array</td><td>List of numbers to sum.</td><td><span data-option="749256e4cf85463181ee3afefe9c10b2">Number Array</span></td><td>true</td></tr><tr><td>format</td><td><a href="/pages/-M_x4dVDz1v6rNxxMMP9#standard">Format string</a> used to format the result</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>false</td></tr></tbody></table>

**Example**&#x20;

{% tabs %}
{% tab title="Template" %}

```javascript
{{$sum hours_worked}}
```

{% endtab %}

{% tab title="Data" %}

```json
{
    "hours_worked": [3, 6, 4, 12]
}
```

{% endtab %}

{% tab title="Result" %}
25
{% endtab %}
{% endtabs %}

####

#### **Returns**

Returns the total.
{% endtab %}

{% tab title="Signature 2" %}
`{{$sum number1 number2 [...] [format]}}`

Computes the sum of numbers passed as arguments.&#x20;

#### Arguments&#x20;

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option><option value="749256e4cf85463181ee3afefe9c10b2" label="Number Array" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>number1</td><td>The first number to sum.</td><td><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number</span></td><td>true</td></tr><tr><td>number2</td><td>The second number to sum.</td><td><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number</span></td><td>true</td></tr><tr><td>[...]</td><td>The remaining numbers to sum.</td><td><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number</span></td><td>false</td></tr><tr><td>format</td><td><a href="/pages/-M_x4dVDz1v6rNxxMMP9#standard">Format string</a> used to format the result</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>false</td></tr></tbody></table>

**Example**&#x20;

{% tabs %}
{% tab title="Template" %}

```javascript
{{$sum subtotal discount tax}}
```

{% endtab %}

{% tab title="Data" %}

```json
{
    "subtotal": 150,
    "discount": -20,
    "tax": 6.50
}
```

{% endtab %}

{% tab title="Result" %}
136.5
{% endtab %}
{% endtabs %}

####

#### **Returns**

Returns the total.
{% endtab %}

{% tab title="Signature 3" %}
`{{$sum collection path [format]}}`

Computes the sum of [numbers](broken://pages/-Mf-KWZIw6EzwOISMYUi#numbers) within a [collection](broken://pages/-Mf-KWZIw6EzwOISMYUi#collections) (an [array](broken://pages/-Mf-KWZIw6EzwOISMYUi#arrays) of [objects](broken://pages/-Mf-KWZIw6EzwOISMYUi#objects)).

#### Arguments&#x20;

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option><option value="749256e4cf85463181ee3afefe9c10b2" label="Number Array" color="blue"></option><option value="44aa8fd70a3e417f9d7fd0c5598d7442" label="Collection" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>collection</td><td>An array of objects</td><td><span data-option="44aa8fd70a3e417f9d7fd0c5598d7442">Collection</span></td><td>true</td></tr><tr><td>path</td><td>Path to the number property on each object.</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>true</td></tr><tr><td>format</td><td><a href="/pages/-M_x4dVDz1v6rNxxMMP9#standard">Format string</a> used to format the result</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>false</td></tr></tbody></table>

**Example**&#x20;

{% tabs %}
{% tab title="Template" %}

```javascript
{{$sum items "price"}}
```

{% endtab %}

{% tab title="Data" %}

```json
{
    "items": [
        { "name":"Rocket Skates", "price":160.3 },
        { "name":"Acme Glue", "price":15.6 },
        { "name":"Wing Suit", "price":699.99 },
    ]
}
```

{% endtab %}

{% tab title="Result" %}
875.89
{% endtab %}
{% endtabs %}

####

#### **Returns**

Returns the total.
{% endtab %}
{% endtabs %}

### $min <a href="#min" id="min"></a>

Computes the minimum number in an array.

#### Signature

`{{$min array [format]}}`

#### Arguments

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option><option value="f33f9bdfa8874e71ac20e6f971d27573" label="Number Array" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>array</td><td>Array of numbers.</td><td><span data-option="f33f9bdfa8874e71ac20e6f971d27573">Number Array</span></td><td>true</td></tr><tr><td>format</td><td><a href="/pages/-M_x4dVDz1v6rNxxMMP9#standard">Format string</a> used to format the result</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>false</td></tr></tbody></table>

#### **Returns**

Returns the minimum value.

**Example**

{% tabs %}
{% tab title="Template" %}

```javascript
{{$min scores}}
```

{% endtab %}

{% tab title="Data" %}

```json
{
    "scores": [ 3, 22, 9, 15 ]
}
```

{% endtab %}

{% tab title="Result" %}
3
{% endtab %}
{% endtabs %}

### $max <a href="#max" id="max"></a>

Computes the maximum number in an array.

#### Signature

`{{$max array [format]}}`

#### Arguments

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option><option value="f33f9bdfa8874e71ac20e6f971d27573" label="Number Array" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>array</td><td>Array of numbers.</td><td><span data-option="f33f9bdfa8874e71ac20e6f971d27573">Number Array</span></td><td>true</td></tr><tr><td>format</td><td><a href="/pages/-M_x4dVDz1v6rNxxMMP9#standard">Format string</a> used to format the result</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>false</td></tr></tbody></table>

#### **Returns**

Returns the maiximum value.

**Example**

{% tabs %}
{% tab title="Template" %}

```javascript
{{$max scores}}
```

{% endtab %}

{% tab title="Data" %}

```json
{
    "scores": [ 3, 22, 9, 15 ]
}
```

{% endtab %}

{% tab title="Result" %}
22
{% endtab %}
{% endtabs %}

### $mean <a href="#mean" id="mean"></a>

Computes the average of all values in an array.

#### Signature

`{{$mean array [format]}}`

#### Arguments

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option><option value="f33f9bdfa8874e71ac20e6f971d27573" label="Number Array" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>array</td><td>Array of numbers.</td><td><span data-option="f33f9bdfa8874e71ac20e6f971d27573">Number Array</span></td><td>true</td></tr><tr><td>format</td><td><a href="/pages/-M_x4dVDz1v6rNxxMMP9#standard">Format string</a> used to format the result</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>false</td></tr></tbody></table>

#### **Returns**

Returns the average value.

**Example**

{% tabs %}
{% tab title="Template" %}

```javascript
{{$mean scores}}
```

{% endtab %}

{% tab title="Data" %}

```json
{
    "scores": [ 3, 22, 9, 15 ]
}
```

{% endtab %}

{% tab title="Result" %}
12.25
{% endtab %}
{% endtabs %}

### $round <a href="#round" id="round"></a>

Computes `number` rounded to `precision`.

#### Signature

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

#### Arguments

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option><option value="f33f9bdfa8874e71ac20e6f971d27573" label="Number Array" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>number</td><td>Array of numbers.</td><td><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number</span></td><td>true</td></tr><tr><td>precision</td><td>Decimal precision to round to. <em>Default=0</em></td><td><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number</span></td><td>false</td></tr><tr><td>format</td><td><a href="/pages/-M_x4dVDz1v6rNxxMMP9#standard">Format string</a> used to format the result</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>false</td></tr></tbody></table>

#### **Returns**

Returns the rounded value.

**Example**

{% tabs %}
{% tab title="Template" %}

```javascript
{{$round avg_age}}
```

{% endtab %}

{% tab title="Data" %}

```json
{
    "avg_age": 39.486
}
```

{% endtab %}

{% tab title="Result" %}
39
{% endtab %}
{% endtabs %}

### $floor <a href="#floor" id="floor"></a>

Computes `number` rounded down to `precision`.

#### Signature

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

#### Arguments

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option><option value="f33f9bdfa8874e71ac20e6f971d27573" label="Number Array" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>number</td><td>Array of numbers.</td><td><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number</span></td><td>true</td></tr><tr><td>precision</td><td><p>Decimal precision to round down to. </p><p><em>Default=0</em></p></td><td><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number</span></td><td>false</td></tr><tr><td>format</td><td><a href="/pages/-M_x4dVDz1v6rNxxMMP9#standard">Format string</a> used to format the result</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>false</td></tr></tbody></table>

#### **Returns**

Returns the rounded down value.

**Example**

{% tabs %}
{% tab title="Template" %}

```javascript
{{$floor avg_age}}
```

{% endtab %}

{% tab title="Data" %}

```json
{
    "avg_age": 39.682
}
```

{% endtab %}

{% tab title="Result" %}
39
{% endtab %}
{% endtabs %}

### $ceil <a href="#ceil" id="ceil"></a>

Computes `number` rounded up to `precision`.

#### Signature

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

#### Arguments

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option><option value="f33f9bdfa8874e71ac20e6f971d27573" label="Number Array" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>number</td><td>Array of numbers.</td><td><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number</span></td><td>true</td></tr><tr><td>precision</td><td><p>Decimal precision to round down to. </p><p><em>Default=0</em></p></td><td><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number</span></td><td>false</td></tr><tr><td>format</td><td><a href="/pages/-M_x4dVDz1v6rNxxMMP9#standard">Format string</a> used to format the result</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>false</td></tr></tbody></table>

#### **Returns**

Returns the rounded-up value.

**Example**

{% tabs %}
{% tab title="Template" %}

```javascript
{{$ceil avg_age}}
```

{% endtab %}

{% tab title="Data" %}

```json
{
    "avg_age": 39.182
}
```

{% endtab %}

{% tab title="Result" %}
40
{% endtab %}
{% endtabs %}

## List/Arrays

### #each <a href="#each" id="each"></a>

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

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option><option value="cebed7abfeee4c25af96f5c9466ac453" label="String Array" color="blue"></option><option value="8a76c273e1c54778b694497f2a693355" label="Number Array" color="blue"></option><option value="addea9408e6745c9be865b7e946eabca" label="Boolean Array" color="blue"></option><option value="84571f0adb4e4f3daf96174af67f175a" label="Object Array" color="blue"></option><option value="1e4385b940ee4a27a0a2bb649df86e6d" label="Array Array" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>array</td><td>List of items to repeat/loop over</td><td><span data-option="cebed7abfeee4c25af96f5c9466ac453">String Array, </span><span data-option="8a76c273e1c54778b694497f2a693355">Number Array, </span><span data-option="addea9408e6745c9be865b7e946eabca">Boolean Array, </span><span data-option="84571f0adb4e4f3daf96174af67f175a">Object Array, </span><span data-option="1e4385b940ee4a27a0a2bb649df86e6d">Array Array</span></td><td>true</td></tr></tbody></table>

#### **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.&#x20;

{% tabs %}
{% tab title="Template" %}

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

{% endtab %}

{% tab title="Data" %}

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

{% endtab %}

{% tab title="Result" %}
Wile E. Coyote, Road Runner&#x20;
{% endtab %}
{% endtabs %}

#### **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.

{% tabs %}
{% tab title="Template" %}

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

{% endtab %}

{% tab title="Data" %}

```json
{
    "characters": [ "Wile E. Coyote", "Road Runer" ]
}
```

{% endtab %}

{% tab title="Result" %}
Wile E. Coyote, Road Runner&#x20;
{% endtab %}
{% endtabs %}

### $filter <a href="#filter" id="filter"></a>

Filters an array/list of items.

#### Signature

`{{$filter array` [`path`](broken://pages/ABxtwZEqy7Nm8F6f8MWG#path)[`operator`](broken://pages/F81mkpgvzTOk4bSyonvu) `[value]}}`

#### Arguments

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option><option value="fe749c5299b341f8a6aaa533ce045b4d" label="String Array" color="blue"></option><option value="525618894ebe442ca9721339fc729e56" label="Number Array" color="blue"></option><option value="d5f34c3a9e6d4a0da0490ee7be091a26" label="Object Array" color="blue"></option><option value="72a2ef6ca94a4272bc70b7acaceec18e" label="" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>array</td><td>Accepts either an array of data or a relative <a href="/pages/ABxtwZEqy7Nm8F6f8MWG#path">path</a>, as a String, to an array.</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String, </span><span data-option="fe749c5299b341f8a6aaa533ce045b4d">String Array, </span><span data-option="525618894ebe442ca9721339fc729e56">Number Array, </span><span data-option="d5f34c3a9e6d4a0da0490ee7be091a26">Object Array</span></td><td>true</td></tr><tr><td><a href="/pages/ABxtwZEqy7Nm8F6f8MWG#path">path</a></td><td><p>Path to property if looping over an array/list of Objects. </p><p><strong>Note</strong>: If looping over a list of Strings, Numbers or Booleans then this should be the <a href="/pages/F81mkpgvzTOk4bSyonvu">operator</a>.</p></td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>true</td></tr><tr><td><a href="/pages/F81mkpgvzTOk4bSyonvu">operator</a></td><td><p>The operator used to evaluate each item in the array/list. </p><p><strong>Note</strong>: If looping over an array/list of Strings, Numbers or Booleans then this should be the value to check against.</p></td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>true</td></tr><tr><td>value</td><td>The value to compare variable's value to. Required when using an operator that requries two arguments.</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String, </span><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number, </span><span data-option="011b91dfe58a400894b04549ec4f9e02">Boolean</span></td><td>false</td></tr></tbody></table>

#### Example - Array of Objects

{% tabs %}
{% tab title="Template" %}

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

{% endtab %}

{% tab title="Data" %}

```json
{
  "products": [
    { "name":"Batman Costume", "category":"Disguise" }, 
    { "name":"TNT", "category":"Explosive" },
    { "name":"Jet-Propelled Unicycle", "category":"Transportation" }
  ]
}
```

{% endtab %}

{% tab title="Result" %}

```json
[
  { "name":"Batman Costume", "category":"Disguise" }, 
  { "name":"TNT", "category":"Explosive" }
]
```

{% endtab %}
{% endtabs %}

Video walk-through of the filter process

{% embed url="<https://youtu.be/zd0XL-SQFGo>" %}

### $group <a href="#group" id="group"></a>

Group items together and create a loop of those items

Video walk-through of the group process

{% embed url="<https://youtu.be/P_uoqYdHnwU>" %}

### $join <a href="#join" id="join"></a>

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

#### Signature

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

#### Arguments

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option><option value="fe749c5299b341f8a6aaa533ce045b4d" label="String Array" color="blue"></option><option value="525618894ebe442ca9721339fc729e56" label="Number Array" color="blue"></option><option value="d5f34c3a9e6d4a0da0490ee7be091a26" label="Object Array" color="blue"></option><option value="72a2ef6ca94a4272bc70b7acaceec18e" label="" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>array</td><td>Accepts either an array of data or a relative <a href="/pages/ABxtwZEqy7Nm8F6f8MWG#path">path</a>, as a String, to an array.</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String, </span><span data-option="fe749c5299b341f8a6aaa533ce045b4d">String Array, </span><span data-option="525618894ebe442ca9721339fc729e56">Number Array, </span><span data-option="d5f34c3a9e6d4a0da0490ee7be091a26">Object Array</span></td><td>true</td></tr><tr><td>path</td><td><p>If the array is a collection (an array of objects) then use this <a href="/pages/ABxtwZEqy7Nm8F6f8MWG#path">path</a> to specify which property in the object should be concatenated.</p><p><mark style="color:blue;"><strong>Default value</strong></mark>: ", "</p></td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>false</td></tr><tr><td>separator</td><td>String that separates each item in the array.</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>false</td></tr><tr><td>final</td><td>The string that's used to separate the last two items.</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>false</td></tr></tbody></table>

#### Example #1 - Array of strings

{% tabs %}
{% tab title="Template" %}

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

{% endtab %}

{% tab title="Data" %}

```json
{
  "categories": ["Disguise", "Explosive", "Transportation"]
}
```

{% endtab %}

{% tab title="Result" %}
Disguise, Maintenance & Transportation
{% endtab %}
{% endtabs %}

#### Example #2- Collection (array of objects)

{% tabs %}
{% tab title="Template" %}

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

{% endtab %}

{% tab title="Data" %}

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

{% endtab %}

{% tab title="Result" %}
Glue V1, Artificial Rock & Bat-Man's Outfit
{% endtab %}
{% endtabs %}

#### Example #3 - Path to array

{% tabs %}
{% tab title="Template" %}

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

{% endtab %}

{% tab title="Data" %}

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

{% endtab %}

{% tab title="Result" %}
Bernadine Burton, Good Battle & Dennis Miles
{% endtab %}
{% endtabs %}

## Helpers

### $extname <a href="#extname" id="extname"></a>

Returns the extension name of a filename.

#### Signature

`{{$extname filename }}`

#### Arguments

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option><option value="fe749c5299b341f8a6aaa533ce045b4d" label="String Array" color="blue"></option><option value="525618894ebe442ca9721339fc729e56" label="Number Array" color="blue"></option><option value="d5f34c3a9e6d4a0da0490ee7be091a26" label="Object Array" color="blue"></option><option value="72a2ef6ca94a4272bc70b7acaceec18e" label="" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>filename</td><td>The name of the file that you're trying to get the extension name of.</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>true</td></tr></tbody></table>

#### Example

{% tabs %}
{% tab title="Template" %}

```
{{$extname filename}}
```

{% endtab %}

{% tab title="Data" %}

```json
{
  "filename": "https://acmec.co/assets/image.jpg"
}
```

{% endtab %}

{% tab title="Result" %}
jpg
{% endtab %}
{% endtabs %}

### $inspect <a href="#inspect" id="inspect"></a>

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

#### Signature

`{{$inspect [expandDepth=1]}}`

#### Arguments

<table><thead><tr><th width="169">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option><option value="fe749c5299b341f8a6aaa533ce045b4d" label="String Array" color="blue"></option><option value="525618894ebe442ca9721339fc729e56" label="Number Array" color="blue"></option><option value="d5f34c3a9e6d4a0da0490ee7be091a26" label="Object Array" color="blue"></option><option value="72a2ef6ca94a4272bc70b7acaceec18e" label="" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>expandDepth</td><td>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]</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String, </span><span data-option="6a3ca9c830be4cd5a2bcf10d17c44f82">Number</span></td><td>false</td></tr></tbody></table>

#### Example

{% tabs %}
{% tab title="Template" %}

```handlebars
{{$inspect 2}}
```

{% endtab %}

{% tab title="Data" %}

```json
{
    "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 },
    ]
}
```

{% endtab %}

{% tab title="Result" %}
![](/files/4VPkk9uwpXRviD8mif8P)
{% endtab %}
{% endtabs %}

## Content

### $iframe <a href="#iframe" id="iframe"></a>

Documentation coming soon!

### $link

Creates a link to a given URL

#### Signature

`{{$link url [text]}}`

#### Arguments

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>url</td><td>URL value of the link</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>true</td></tr><tr><td>text</td><td>Text to display in document. If no value is provided the URL of the link will be displayed</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>false</td></tr></tbody></table>

#### **Returns**

Link to the given URL.

**Example**

{% tabs %}
{% tab title="Template" %}

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

{% endtab %}

{% tab title="Data" %}

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

{% endtab %}

{% tab title="Result" %}
<https://www.acme.co>

[Acme Co.](https://www.acme.co)
{% endtab %}
{% endtabs %}

### $md <a href="#md" id="md"></a>

Renders markdown content

#### Signature

`{{$md content}}`

#### Arguments

<table><thead><tr><th width="150">Name</th><th width="272.5333333333333">Description</th><th width="150">Type<select multiple><option value="b0403385da1b4af9a8a894cb7cfa1e88" label="String" color="blue"></option><option value="6a3ca9c830be4cd5a2bcf10d17c44f82" label="Number" color="blue"></option><option value="011b91dfe58a400894b04549ec4f9e02" label="Boolean" color="blue"></option><option value="3c1342f6b38a46e39064bd88015df50d" label="Any" color="blue"></option></select></th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>content</td><td>Markdown content</td><td><span data-option="b0403385da1b4af9a8a894cb7cfa1e88">String</span></td><td>true</td></tr></tbody></table>

#### **Example**

{% tabs %}
{% tab title="Template" %}

```handlebars
{{$md notes}}
```

{% endtab %}

{% tab title="Data" %}

```json
{
    "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"
}
```

{% endtab %}

{% tab title="Result" %}
![](/files/GtS0jEcVfU3sx98Bpkr7)
{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Troubleshooting**

Spaces at the end of content  wrapped in tags such as \*\* will render the tags as raw text.&#x20;

**Example:**

`"Howdy, **Partner! **"` renders as \*\*Howdy, Partner! \*\*

`"Howdy, **Partner!**" renders as Howdy,`` `**`Partner!`**
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.documint.me/legacy-documentation/data-and-variables/functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
