2020-04-30 18:24:59 -05:00
+++
title = "Advanced variable format options"
keywords = ["grafana", "templating", "documentation", "guide", "template", "variable"]
2020-10-01 16:37:26 -05:00
weight = 600
2020-04-30 18:24:59 -05:00
+++
# Advanced variable format options
2020-11-09 14:26:49 -06:00
The formatting of the variable interpolation depends on the data source, but there are some situations where you might want to change the default formatting.
2020-04-30 18:24:59 -05:00
For example, the default for the MySql data source is to join multiple values as comma-separated with quotes: `'server01','server02'` . In some cases, you might want to have a comma-separated string without quotes: `server01,server02` . You can make that happen with advanced variable formatting options listed below.
## General syntax
Syntax: `${var_name:option}`
Test the formatting options on the [Grafana Play site ](https://play.grafana.org/d/cJtIfcWiz/template-variable-formatting-options?orgId=1 ).
If any invalid formatting option is specified, then `glob` is the default/fallback option.
An alternative syntax (that might be deprecated in the future) is `[[var_name:option]]` .
## CSV
2020-05-06 11:43:52 -05:00
Formats variables with multiple values as a comma-separated string.
2020-04-30 18:24:59 -05:00
```bash
servers = ['test1', 'test2']
String to interpolate: '${servers:csv}'
Interpolation result: 'test1,test2'
```
## Distributed - OpenTSDB
2020-05-06 11:43:52 -05:00
Formats variables with multiple values in custom format for OpenTSDB.
2020-04-30 18:24:59 -05:00
```bash
servers = ['test1', 'test2']
String to interpolate: '${servers:distributed}'
Interpolation result: 'test1,servers=test2'
```
## Doublequote
Formats single- and multi-valued variables into a comma-separated string, escapes `"` in each value by `\"` and quotes each value with `"` .
```bash
servers = ['test1', 'test2']
String to interpolate: '${servers:doublequote}'
Interpolation result: '"test1","test2"'
```
## Glob - Graphite
2020-05-06 11:43:52 -05:00
Formats variables with multiple values into a glob (for Graphite queries).
2020-04-30 18:24:59 -05:00
```bash
servers = ['test1', 'test2']
String to interpolate: '${servers:glob}'
Interpolation result: '{test1,test2}'
```
## JSON
2020-05-06 11:43:52 -05:00
Formats variables with multiple values as a comma-separated string.
2020-04-30 18:24:59 -05:00
```bash
servers = ['test1', 'test2']
String to interpolate: '${servers:json}'
Interpolation result: '["test1", "test2"]'
```
## Lucene - Elasticsearch
2020-05-06 11:43:52 -05:00
Formats variables with multiple values in Lucene format for Elasticsearch.
2020-04-30 18:24:59 -05:00
```bash
servers = ['test1', 'test2']
String to interpolate: '${servers:lucene}'
Interpolation result: '("test1" OR "test2")'
```
## Percentencode
Formats single and multi valued variables for use in URL parameters.
```bash
servers = ['foo()bar BAZ', 'test2']
String to interpolate: '${servers:percentencode}'
Interpolation result: 'foo%28%29bar%20BAZ%2Ctest2'
```
## Pipe
2020-05-06 11:43:52 -05:00
Formats variables with multiple values into a pipe-separated string.
2020-04-30 18:24:59 -05:00
```bash
servers = ['test1.', 'test2']
String to interpolate: '${servers:pipe}'
Interpolation result: 'test1.|test2'
```
2020-05-05 16:37:34 -05:00
## Raw
Turns off data source-specific formatting, such as single quotes in an SQL query.
```bash
2020-12-21 09:54:01 -06:00
servers = ['test.1', 'test2']
2020-05-05 16:37:34 -05:00
String to interpolate: '${var_name:raw}'
2020-12-21 09:54:01 -06:00
Interpolation result: 'test.1,test2'
2020-05-05 16:37:34 -05:00
```
2020-04-30 18:24:59 -05:00
## Regex
2020-05-06 11:43:52 -05:00
Formats variables with multiple values into a regex string.
2020-04-30 18:24:59 -05:00
```bash
servers = ['test1.', 'test2']
String to interpolate: '${servers:regex}'
Interpolation result: '(test1\.|test2)'
```
## Singlequote
Formats single- and multi-valued variables into a comma-separated string, escapes `'` in each value by `\'` and quotes each value with `'` .
```bash
servers = ['test1', 'test2']
String to interpolate: '${servers:singlequote}'
Interpolation result: "'test1','test2'"
```
## Sqlstring
Formats single- and multi-valued variables into a comma-separated string, escapes `'` in each value by `''` and quotes each value with `'` .
```bash
servers = ["test'1", "test2"]
String to interpolate: '${servers:sqlstring}'
Interpolation result: "'test''1','test2'"
```
2020-09-14 01:05:51 -05:00
## Text
Formats single- and multi-valued variables into their text representation. For a single variable it will just return the text representation. For multi-valued variables it will return the text representation combined with `+` .
```bash
servers = ["test1", "test2"]
String to interpolate: '${servers:text}'
Interpolation result: "test1 + test2"
2020-12-21 09:54:01 -06:00
```
2021-02-05 00:16:06 -06:00
## Query parameters
Formats single- and multi-valued variables into their query parameter representation. Example: `var-foo=value1&var-foo=value2`
```bash
servers = ["test1", "test2"]
String to interpolate: '${servers:queryparam}'
Interpolation result: "var-servers=test1& var-servers=test2"
```