2022-05-26 23:06:25 +08:00
---
aliases:
- /docs/grafana/latest/reference/templating/
- /docs/grafana/latest/variables/syntax/
keywords:
- grafana
- templating
- documentation
- guide
- template
- variable
title: Variable syntax
weight: 100
---
2020-10-02 05:37:26 +08:00
# Variable syntax
Panel titles and metric queries can refer to variables using two different syntaxes:
- `$varname`
This syntax is easy to read, but it does not allow you to use a variable in the middle of a word.
**Example:** apps.frontend.$server.requests.count
2020-11-10 04:26:49 +08:00
- `${var_name}` Use this syntax when you want to interpolate a variable in the middle of an expression.
2022-06-03 00:57:22 +08:00
- `${var_name:<format>}` This format gives you more control over how Grafana interpolates values. Refer to [Advanced variable format options ]({{< relref "advanced-variable-format-options/" >}} ) for more detail on all the formatting types.
2020-11-10 04:26:49 +08:00
- `[[varname]]` Do not use. Deprecated old syntax, will be removed in a future release.
2020-10-02 05:37:26 +08:00
Before queries are sent to your data source the query is _interpolated_ , meaning the variable is replaced with its current value. During
interpolation, the variable value might be _escaped_ in order to conform to the syntax of the query language and where it is used.
For example, a variable used in a regex expression in an InfluxDB or Prometheus query will be regex escaped. Read the data source specific
documentation topic for details on value escaping during interpolation.
2022-06-03 00:57:22 +08:00
For advanced syntax to override data source default formatting, refer to [Advanced variable format options ]({{< relref "advanced-variable-format-options/" >}} ).