From 7bc97d5fa8af96a32aaf9787fd5a492253b069cf Mon Sep 17 00:00:00 2001 From: Seunghun Shin <42256738+softho0n@users.noreply.github.com> Date: Thu, 16 Oct 2025 02:28:10 +0900 Subject: [PATCH] Docs: Add contact point specific text formatting examples (#112276) * Docs: Add contact point specific text formatting examples to notification templates * Add Slack formatting examples with *bold* and _italic_ syntax * Clarify that text formatting depends on contact point type * Docs: Add contact point specific text formatting examples to notification templates * Reflect review that fix docs --- .../template-notifications/examples.md | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/docs/sources/alerting/configure-notifications/template-notifications/examples.md b/docs/sources/alerting/configure-notifications/template-notifications/examples.md index 7927d367c94..f44ada3c4bf 100644 --- a/docs/sources/alerting/configure-notifications/template-notifications/examples.md +++ b/docs/sources/alerting/configure-notifications/template-notifications/examples.md @@ -89,7 +89,53 @@ This page provides various examples illustrating how to template common notifica Notification templates can access the [notification data](ref:reference-notification-data) using the dot (`.`). The following examples demonstrate some basic uses of the [template language](ref:language). -For instance, to check if there are common labels (`.CommonLabels`) for all alerts in the notification, use `if`: +### Text formatting examples + +Text formatting in notification templates varies by contact point type. Each platform has its own formatting syntax: + +#### Slack formatting + +For Slack contact points, you can use: + +```go +{{ define "slack_formatted_message" -}} +*This text will be bold in Slack* +_This text will be italic in Slack_ +Regular text without formatting +{{ end }} +``` + +Execute the template: + +```go +{{ template "slack_formatted_message" . }} +``` + +```template_output +*This text will be bold in Slack* +_This text will be italic in Slack_ +Regular text without formatting +``` + +#### Additional contact point types + +{{< admonition type="note" >}} +Each contact point type has its own formatting requirements: + +- Some support Markdown-style formatting +- Others use HTML tags +- Some may not support formatting at all + +Check your specific contact point's documentation for supported formatting syntax. +{{< /admonition >}} + +## Template logic examples + +Beyond text formatting, you can use template logic to create dynamic notification content. The following examples demonstrate basic template operations: + +### Conditional logic + +To check if there are common labels (`.CommonLabels`) for all alerts in the notification, use `if`: ```go {{ define "custom_message" -}} @@ -101,6 +147,8 @@ There are no common labels {{ end }} ``` +### Iterating over alerts + To iterate on the alerts in the notification and print a specific label, use `range` and `index`: ```go