[v9.4.x] Docs: Add example to extract a specific label value (#66018)

Docs: Add the index function

(cherry picked from commit a39190b613)

Co-authored-by: Simon Crute <simonc6372@users.noreply.github.com>
This commit is contained in:
Grot (@grafanabot)
2023-04-05 15:15:53 +01:00
committed by GitHub
co-authored by Simon Crute
parent 1148da45d3
commit 876f6e8727
@@ -71,6 +71,16 @@ The name of the annotation is {{ .Name }}, and the value is {{ .Value }}
{{ end }}
```
## The index function
To print a specific annotation or label use the `index` function.
```
{{ range .Alerts }}
The name of the alert is {{ index .Labels "alertname" }}
{{ end }}
```
## If statements
You can use if statements in templates. For example, to print `There are no alerts` if there are no alerts in `.Alerts` you would write the following: