| `and` | Returns the boolean AND of its arguments by returning the first empty argument or the last argument. |
| `call` | Returns the result of calling the first argument, which must be a function, with the remaining arguments as parameters. |
| `html` | Returns the escaped HTML equivalent of the textual representation of its arguments. |
| `index` | Returns the result of indexing its first argument by the following arguments, e.g., `{{ index $labels "instance" }}` returns the `instance` key in the `$labels` map variable. |
| `slice` | Returns the result of slicing its first argument by the remaining arguments. |
| `js` | Returns the escaped JavaScript equivalent of the textual representation of its arguments. |
| `len` | Returns the integer length of its argument, e.g., `{{ len $array }}` |
| `not` | Returns the boolean negation of its single argument. |
| `or` | Returns the boolean OR of its arguments by returning the first non-empty argument or the last argument. |
| `print` | An alias for fmt.Sprint |
| `printf` | An alias for fmt.Sprintf |
| `println` | An alias for fmt.Sprintln |
| `urlquery` | Returns the escaped value of the textual representation of its arguments in a form suitable for embedding in a URL query |
For more details, refer to the official documentation on [functions in `text/template`](https://pkg.go.dev/text/template#hdr-Functions).
## Comparison operators
Boolean comparison operators are also available in `text/template`:
| `eq` | Returns the boolean truth of arg1 == arg2 |
| `ne` | Returns the boolean truth of arg1 != arg2 |
| `lt` | Returns the boolean truth of arg1 <arg2|
| `le` | Returns the boolean truth of arg1 <= arg2 |
| `gt` | Returns the boolean truth of arg1 > arg2 |
| `ge` | Returns the boolean truth of arg1 >= arg2 |
## Variables
Variables in `text/template` must be created within the template. For example, you can create a variable with the current value of dot (`.`) and assign a string or another object to the variable like this:
```go
{{ $variable := . }}
{{ $variable := "This is a test" }}
{{ $variable }}
```
This template outputs:
```
This is a test
```
## Templates
You can create reusable templates that can be executed from other templates or within the same template.
Define templates using `define` and the name of the template in double quotes:
```go
{{ define "print_labels" }}
{{ end }}
```
You should not define templates with the same name as other templates, including default templates such as `__subject`, `__text_values_list`, `__text_alert_list`, `default.title` and `default.message`. Where a template has been created with the same name as a default template, or a template in another notification template, Grafana might use either template. Grafana does not prevent, or show an error message, when there are two or more templates with the same name.
### Execute templates
You can execute defined templates using `template`, the name of the template in double quotes, and the cursor that should be passed to the template:
```go
{{ template "print_labels" . }}
```
Within a template dot refers to the value that is passed to the template.
For example, if a template is passed a list of firing alerts then dot refers to that list of firing alerts:
```go
{{ template "print_alerts" .Alerts }}
```
If the template is passed the sorted labels for an alert then dot refers to the list of sorted labels:
```go
{{ template "print_labels" .SortedLabels }}
```
This is useful when writing reusable templates. For example, to print all alerts you might write the following:
```go
{{ template "print_alerts" .Alerts }}
```
Then to print just the firing alerts you could write this:
```go
{{ template "print_alerts" .Alerts.Firing }}
```
This works because both `.Alerts` and `.Alerts.Firing` is a list of alerts.
You cannot create independent, reusable templates for labels and annotations as you can with notification templates. In alert rule templates, you need to write each template inline within the label or annotation field.