# Tera syntax quick reference

Use this guide to build and troubleshoot Tera expressions in Notification Center. Tera syntax powers dynamic templating for connectors, presets, and routing rules.

## Basic syntax

| Type            | Example                                                   | Description                       |
| --------------- | --------------------------------------------------------- | --------------------------------- |
| **Variable**    | `{{ alertDef.name }}`                                     | Displays the value of a variable. |
| **Conditional** | `{% if alert.status == "Triggered" %}...{% endif %}`      | Adds logic to control output.     |
| **Loop**        | `{% for i in alert.groups %}{{ i.priority }}{% endfor %}` | Iterates through a list.          |

## Comparison operators

| Operator                | Example                         | Description              |
| ----------------------- | ------------------------------- | ------------------------ |
| `==`                    | `alert.highestPriority == "P1"` | Equal to                 |
| `!=`                    | `alert.status != "Resolved"`    | Not equal                |
| `>` , `<` , `>=` , `<=` | `alert.value > 80`              | Greater/less comparisons |

## Logical operators

| Operator | Example                                                         | Description         |
| -------- | --------------------------------------------------------------- | ------------------- |
| `and`    | `alert.highestPriority == "P1" and alert.status == "Triggered"` | Both must be true   |
| `or`     | `alert.highestPriority == "P1" or alertDef.priority == "P2"`    | Either can be true  |
| `not`    | `not alert.status == "Resolved"`                                | Negates a condition |

## String tests

| Function             | Example                                         | Result                               |
| -------------------- | ----------------------------------------------- | ------------------------------------ |
| `is starting_with()` | `alertDef.name is starting_with("CPU")`         | `true` if the name begins with CPU   |
| `is containing()`    | `alertDef.description is containing("latency")` | `true` if the text includes the word |
| `is matching()`      | `alertDef.name is matching("(?i)^cpu")`         | Regex match                          |

## Filters

Filters transform or format values. Apply them with a pipe (`|`).

| Filter        | Example                    |
| ------------- | -------------------------- |
| `default`     | \`{{ alert.highestPriority |
| `date`        | \`{{ alert.timestamp       |
| `json_encode` | \`{{ get_context()         |
| `json_escape` | \`{{ alert.groups          |
| `lower`       | \`{{ alertDef.name         |
| `replace`     | \`{{ alertDef.name         |

## Boolean conditions in routing rules

Routing rule conditions must evaluate to `true` or `false`.\
Do **not** wrap conditions in `{{ }}`—enter only the expression.

| Example                                       | Description                          |
| --------------------------------------------- | ------------------------------------ |
| `alert.highestPriority == "P1"`               | Routes only P1 alerts                |
| `alertDef.name is containing("CPU")`          | Routes alerts with “CPU” in the name |
| `alertDef.entityLabels.environment == "prod"` | Routes based on environment          |
| `true`                                        | Always triggers                      |

Note

- Use `{{ get_context() | json_encode(pretty=true) }}` to print all available variables.
- Wrap optional values with `default()` to avoid errors.
- Missing variables cause expressions to evaluate to `false`.
- Keep expressions readable—avoid complex logic in message fields.

## Next steps

Build, validate, and troubleshoot Tera templates in [Tera usage and troubleshooting](https://coralogix.com/docs/user-guides/notification-center/dynamic-templating/tera-usage/index.md).
