Skip to main content

Recipes

Useful snippets that you can use in your templates.

Markdown list from variable

{{#each (variable "hostname")}}

- {{this}}

{{/each}}

Conditional content

{{#if app "auth"}}
This is the auth app.
{{/if}}

Render HTML from data

If you'd like to render HTML returned by the data source, you need to use three-brace expressions, {{{htmlValue}}}, otherwise Handlebars escapes the HTML content.

<ul>
{{{htmlValue}}}
</ul>

where htmlValue is

<li>foo</li>
<li>bar</li>

Dynamic templates using dashboard variables

Use the lookup helper function to create dynamic templates based on dashboard variables.

The following template creates a key-value pair from every selected value in the myvar dashboard variable.

```yml
book:
{{#each (variable "props")}}
{{this}}: {{lookup @root this}}
{{/each}}
```

Render a single template

For the following query result:

titleauthoryear
DuneFrank Herbert1965
1984George Orwell1949

Given that the Every Row switch is turned off, the following template renders a table from the query result:

| Title | Author | Year |
| ----- | ------ | ---- |

{{#each data}}
| {{title}} | {{author}} | {{year}} |
{{/each}}