# $var

{% 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 %}


---

# 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/templates/working-with-dynamic-data/functions-and-operators/usdvar.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.
