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

![](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 %}
