Skip to main content

Helpers

Helpers, sometimes called handlebars, are functions that allow you to perform basic text transformations within your template.

In the JavaScript->before rendering content option a user can register custom handlebars.

The Business Text panel has plenty of predefined handlebars that are registered automatically and ready to use:

HandlebarDescription
containsChecks if a given value exists within an array
dateFormats the timestamp in a given field using a date format
eqChecks two strings for equality
joinJoins all elements of an array into a string using a given separator
jsonPresents an object (JSON) or an array as a formatted string
splitSplits a string into an array using a given separator
toFixedFormats the given number using a fixed-point notation
startsWithReturns true if the variable starts with a specified value
endsWithReturns true if the variable ends with a specified value
matchReturns true if the variable matches with a specified value
variableThis helper works only with one format of Grafana dashboard variables
variableValueThis helper works with all Grafana variable formats

{{contains}}

Checks if a given value exists within an array.

<!-- array: ['a', 'b', 'c'] -->

{{#if (contains array "a")}}
Success!
{{else}}
Not Found!
{{/if}}

<!-- result: 'Success!' -->

{{date}}

Formats the timestamp in a given field using a date format. Uses helper-date.

The field value must be a Unix timestamp or any of the formats supported by the date.js library.

<!-- Time: 1598791377556 -->

{{date Time "YYYY-MM-DD"}}

<!-- result: '2020-08-30' -->

{{eq}}

Checks two strings for equality.

<!-- app: foo -->

{{#if (eq app "auth")}}
This is the auth app.
{{else}}
This is not an auth app.
{{/if}}

<!-- result: 'Success!' -->

{{join}}

Joins all elements of an array into a string using a given separator.

<!-- array: ['a', 'b', 'c'] -->

{{join array "-"}}

<!-- result: 'a-b-c' -->

{{json}}

Presents an object (JSON) or an array as a formatted string. Markdown supports the syntax highlighting.

<!-- object or array -->

```json
{{json obj}}
```

<!-- result: as string -->
Visualize a formatted JSON object.
Visualize a formatted JSON object.

Transformation

The JSON helper expects an object or an array to display it as a formatted string. If the data source returns a string it should be transformed to a JSON object using the Convert field type transformation.

Transform a JSON string into an object.
Transform a JSON string into an object.

{{split}}

Splits a string into an array using a given separator.

<!-- string: 'a,b,c,d' -->

{{split str ","}}

<!-- result: ['a','b','c'] -->
Examples of splitting a string into an array.
Examples of splitting a string into an array.

{{toFixed}}

Formats the given number using a fixed-point notation.

<!-- Value: 1.1234 -->

{{toFixed Value 2}}

<!-- result: '1.12' -->

{{startsWith}}

Version

The Business Text panel supports this starting from version 4.2.0.

Returns true if the variable starts with a specified value. Example:

|Name| My Value| |---|---|
{{#each @root}}
{{#if (startsWith @key "My_")}}
| {{@key}} | {{this}} |
{{/if}}
{{/each}}

{{endsWith}}

Version

The Business Text panel supports this starting from version 4.2.0.

Returns true if the variable ends with a specified value. Example:

|Name| My Keys| |---|---|
{{#each @root}}
{{#if (endsWith @key "_key")}}
| {{@key}} | {{this}} |
{{/if}}
{{/each}}=

{{match}}

Version

The Business Text panel supports this starting from version 4.2.0.

Returns true if the variable matches with a specified value. Example:

|Key| Value| |---|---|
{{#each @root}}
{{#if (match @key "^(Country|Street|Post)")}}
| {{@key}} | {{this}} |
{{/if}}
{{/each}}

Helper {{variable}}

This helper works only with one format of Grafana dashboard variables - array.

It returns a string array including the currently selected values for a certain variable.

{{variable "hostname"}}

if hostname = ["server1", "server2", "server3"] then result: ["server1",
"server2", "server3"]

Helper {{variableValue}}

Version

The Business Text panel supports this starting from version 4.3.0.

This helper works with all Grafana variable formats. Below is an example of the queryparam type.

<a href="/d/abc?{{variableValue '${example:queryparam}'}}">Link</a>

If example equal to ["value1", "value2"] then result:

<a href="/d/abc?var-example=value1&var-example=value2">Link</a>