# Template Variables

### Template Variable Assignments

Sometimes you want to calculate some value based on data input and reuse it across the document. You can do that using assignments within smart fields then you can use assign value within Smart Fields or Smart Sections Multiple Times

```
Cost of labor: {labor} USD
Cost of parts: {parts} USD

Total Cost: {$ total = labor+parts } USD

Total Cost + Tax: {$ total * 1.22 } USD (Including 22% Tax)

{#$ total > 1000 }
Warning! Your total net cost exceeds 1000 USD
{/}
```

### Hidden Variables

You can combine variables with a [hide formatter](https://docs.documentero.com/documentation/fields-formatters#special-field-formatter-hide). To create hidden calculated fields that you can use across your template. (E.g. You can define them at the top of the page based on values passed for document generation and use it in your template.

```
Cost of labor: {labor} USD
Cost of parts: {parts} USD
{$ total = (labor+parts) * 1.22 | hide}

Total Cost + Tax: {$ total} USD (Including 22% Tax)
Payment of {$ total} USD is due by 10-10-2026
```

### Conditional Variables

You can combine variables with Smart Fields to use conditions to define multiple reusable values based on passed data.

```
Field value: {sampleField} (Assuming it could be value 'opt1' or 'opt2')

{$ variableName = sampleField == 'opt1' ? 'Text if option 1' : 'Text if not'}
{$ anotherVariableName = sampleField == 'opt1' ? 'Different text if option 1' : 'Different text if not'}
```


---

# 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.documentero.com/documentation/templates/template-variables.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.
