> For the complete documentation index, see [llms.txt](https://docs.documentero.com/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.documentero.com/documentation/templates/template-variables.md).

# 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](/documentation/templates/fields-formatters.md#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
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 dynamically by asking a question.

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

```
GET https://docs.documentero.com/documentation/templates/template-variables.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
