# Create templates with global variables

In this article:

# Get started

To create templates to build interactive dashboards you can use variables via the $variable or [[variable]] syntax. You can learn more about templates and variables in the Grafana documentation (opens new window).

To add variables for assets to a dashboard in Grafana:

  1. Navigate to your dashboard's settings, and then select Variables from the left side.

  2. Make sure the Type is set to Query, and then set your Cognite Data Source as the Data Source.

  3. Specify the query to fetch and filter assets from CDF. For example:

    assets{parentIds=[123], name=~"test-.*"}
    
    1

    The query above requests assets with the parameter parentIds=[123] and filters the results by name that matches the test-.* regular expression.

    Variable Query

  4. Click Update.

You can format variables to fit into the query, for instance if you have a multi-value variable:

ts{assetIds=[${variable:csv}]}
1

The variable will be serialized to comma-separated values in case several assets are selected from the dropdown. Learn more about formatting of variables in the Grafana documentation (opens new window).

# Nested (chained) variables

With nested variables, you can create a template to visualize time series related to a branch of the asset subtree and let users navigate the subtree.

  1. Create the necessary nested variables.

    Link variables

  2. Use the variable as the asset filter on the dashboard.

    Use the variable on the dashboard

  3. On the dashboard, users can choose assets on each level of the hierarchy.

    Select assets from the dropdown

Last Updated: 6/1/2021, 9:48:27 AM