> For the complete documentation index, see [llms.txt](https://docs.documint.me/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.documint.me/templates/working-with-dynamic-data/functions-and-operators/functions/usdvar.md).

# $var

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.

![](https://1903534506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTY5wPd81K7B5rjyG5tjS%2Fuploads%2F6YjgjbbA7QS3cuWomqjK%2Fimage.png?alt=media\&token=eaf2f96b-3d71-4e20-af60-26c93f995cfb)

Repeat the section for each item in the custom variable

![](https://1903534506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTY5wPd81K7B5rjyG5tjS%2Fuploads%2FDE7OPcKwKKF48Ch43mbT%2Fimage.png?alt=media\&token=d32d3a9b-c6a8-41c9-85c1-364a438d4b29)
{% 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" %}
![](https://1903534506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTY5wPd81K7B5rjyG5tjS%2Fuploads%2FyaaFCzMB3jB1vZEEuh29%2Fimage.png?alt=media\&token=63d7c356-766a-4935-adb7-84b01d5bdc03)
{% endtab %}
{% endtabs %}

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.documint.me/templates/working-with-dynamic-data/functions-and-operators/functions/usdvar.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
