Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

Overview

You can customize Synthetic monitor messages using handlebars templating. The following examples cover advanced techniques such as comments, list access, conditions, and iterations.

Note: Always test your syntax directly in the monitor message editor, as template behavior may vary slightly across versions.

Comments

Use comments to explain what the template is doing. Comments are removed from the final rendered message.

{{! This is a comment }}
{{!
This is a
multi-line comment
}}

Raw strings

To display raw values without HTML escaping (for example, URLs, or HTTP responses in code blocks), use triple curly braces:

{{{my_var}}}
Certain messaging integrations (such as Google) require triple braces {{{ around template variables to ensure proper formatting when the message is displayed. For example, you can use {{{synthetics.attributes.result.failure.message}}}.

Human-readable formatting

Note: All durations are in milliseconds.

  • Durations:

    {{eval "synthetics.attributes.result.duration/1000"}}
    
  • Data Sizes:

    {{eval "humanize_bytes(bodySize)"}}
    

Conditions

Use #if, #is_match, and #is_exact_match for logic-based rendering.

Boolean check:

{{#if synthetics.attributes.variable.config.CONFIG_VAR.secure}}
  The CONFIG_VAR variable is obfuscated
{{else}}
  The CONFIG_VAR variable isn't obfuscated
{{/if}}

Conditional alerting based on step ID

{{!
This alert uses the variable shortcut object `{{synthetics.failed_step}}` to match the step id. If the step id matches, notify the relevant recipient.
}}
{{#is_exact_match synthetics.failed_step.id "svn-yrx-3xg"}}
  A backend-related step failed!
  @slack-backend-team
{{else}}
  Another step failed, probably Frontend related
  @slack-frontend-team
{{/is_exact_match}}
Use #if over #is_exact_match for checking if a variable is empty or unset.

Iteration

Use #each to loop over dictionaries or lists. You can access:

  • this → the current item
  • @key → the current key (for dictionaries)
  • @index, @first, @last → loop metadata

Use local variables in a notification

{{!
The test is configured with three local variables.
The names of the variables are: APP_NAME, APP_URL, and APP_ENVIRONMENT.
The value of the variable can be accessed by passing its name in the config field like `{{synthetics.attributes.result.variables.config[<variable-name>].value}}`
}}
Application: {{synthetics.attributes.result.variables.config[APP_NAME].value}}
URL Tested: {{synthetics.attributes.result.variables.config[APP_URL].value}}
Environment: {{synthetics.attributes.result.variables.config[APP_ENVIRONMENT].value}}

Loop through the steps of a multistep API test

{{! Print out the details of each step }}
{{#each synthetics.attributes.result.steps}}
Step name: {{name}}
Step status: {{status}}
Step type: {{type}}

  {{! Within each step, print out the details of the extracted variable }}
  {{#each variables.extracted}}
    Extracted variable name: {{ name }}
    Extracted variable value: {{ val }}
  {{/each}}

{{/each}}

Loop through the steps of a browser test

{{! Print out the details of each step }}
{{#each synthetics.attributes.result.steps}}

Step name: {{description}}
Step status: {{status}}
Step type: {{type}}

  {{! Print out the details of the extracted variable step }}
  {{#is_match "type" "extractVariable"}}
    Extracted variable name: {{ extractedValue.name }}
    Extracted variable value: {{ extractedValue.value }}
  {{/is_match}}

{{/each}}

Further Reading