Open source Enterprise Grafana Cloud
Last reviewed: August 19, 2026

Template language

Alertmanager templates use Go’s text/template syntax. This page covers the parts you actually need.

Define and use

Every template is a named definition:

Go
{{ define "slack.title" }}
[{{ .Status | toUpper }}] {{ .GroupLabels.alertname }}
{{ end }}

Reference it from another template with template:

Go
{{ template "slack.title" . }}

The trailing . passes the current context through. Leaving it off gives the template no data to work with, which is a common cause of mysteriously empty notifications.

The dot

. is the current context. At the top of a notification template it’s the notification data: the group of alerts and their shared labels. Inside a range it becomes the current item.

Go
{{ .GroupLabels.alertname }}       one field of the notification
{{ range .Alerts }}{{ .Labels.instance }}{{ end }}   .  is now one alert

Losing track of what . refers to is the single most common template bug. Inside a loop, use $ to reach back to the original top-level context:

Go
{{ range .Alerts }}{{ $.GroupLabels.cluster }} — {{ .Labels.instance }}
{{ end }}

Loops and conditionals

Go
{{ range .Alerts }}
- {{ .Annotations.summary }}
{{ end }}
Go
{{ if eq .Status "firing" }}Firing{{ else }}Resolved{{ end }}
Go
{{ if .Alerts.Firing }}{{ len .Alerts.Firing }} firing{{ end }}

Comparison functions are written as functions, not operators: eq, ne, lt, le, gt, ge.

Variables

Go
{{ $count := len .Alerts }}
{{ $count }} alert(s) firing

Useful functions

FunctionDoes
toUpper, toLowerChange case
titleTitle-case a string
joinJoin a list with a separator
lenLength of a list
printfFormat a value, as in printf "%.2f"
match, reReplaceAllRegex match and replace

Whitespace

Go templates keep the whitespace around actions, which is why templates often render with unexpected blank lines. Add a hyphen inside the braces to trim it:

Go
{{- range .Alerts }}
- {{ .Annotations.summary }}
{{- end }}

{{- trims whitespace before the action, -}} trims after.

Writing templates without breaking things

There’s no preview in the plugin, and a broken template shows up when a notification is sent. Build them up in small steps: start with plain static text, confirm it arrives, then add one field at a time.

Refer to Template examples for working starting points, and Template reference for the available fields.