From a39190b6137ea61e194ef5a1fd7e96f83de19cf7 Mon Sep 17 00:00:00 2001 From: Simon Crute Date: Wed, 5 Apr 2023 13:49:57 +0100 Subject: [PATCH] Docs: Add the index function --- .../using-go-templating-language.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/sources/alerting/manage-notifications/template-notifications/using-go-templating-language.md b/docs/sources/alerting/manage-notifications/template-notifications/using-go-templating-language.md index b6529d4f7b2..a1b5267c338 100644 --- a/docs/sources/alerting/manage-notifications/template-notifications/using-go-templating-language.md +++ b/docs/sources/alerting/manage-notifications/template-notifications/using-go-templating-language.md @@ -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: