Dashboard Templating
Templating allows you to create dynamic, reusable dashboards that adapt based on variable values. Template variables can be used throughout your dashboard in queries, panel titles, annotations, and links.Template Syntax
Grafana uses a simple templating syntax for variable interpolation:Variable Interpolation
In Queries
Template variables are most commonly used in data source queries:In Panel Titles
Make panel titles dynamic:In Descriptions
Add context with variable values:In Annotations
Filter annotations using variables:In Links
Create dynamic dashboard and external links:Variable Formats
Apply different formats to variable values:Text Formats
Multi-Value Formats
Date Formats
Format time range variables:Advanced Templating
Nested Variables
Variables can reference other variables:Chained Variables
Create variable dependencies:Conditional Templating
Use variable values to control behavior:Dynamic Panel Repetition
Repeat panels based on variable values:Row Repetition
Repeat entire rows:Built-in Template Variables
Grafana provides several built-in variables:Time Range Variables
Rate Interval
Field Variables (Data Links)
Series Variables (Panel Repeat)
Dashboard Variables
URL Variables
Template Functions
While Grafana doesn’t have built-in template functions, you can achieve similar results:String Manipulation via Regex
Mathematical Operations
Use query expressions:Best Practices
Query Optimization
1
Use Appropriate Refresh
Set
refresh to match data update frequency2
Limit Variable Cardinality
Avoid variables with thousands of values
3
Use Constants for Static Values
Don’t query for values that never change
4
Cache When Possible
Use
onDashboardLoad refresh for static dataNaming Conventions
Variable Organization
Order variables logically:- Data source variables first
- High-level filters (environment, region)
- Mid-level filters (datacenter, cluster)
- Low-level filters (server, pod)
- Display options (interval, aggregation)
- Hidden variables last
Performance Considerations
- Limit variable chains to 3-4 levels max
- Avoid regex on large result sets
- Use multi-value variables sparingly
- Set reasonable
maxPerRowfor repeated panels - Consider hiding variables not needed by users
Common Patterns
Multi-Tenant Dashboards
Environment-Based Configuration
Dynamic Aggregation
Time Window Comparison
Troubleshooting
Variable Not Interpolated
- Check variable name spelling and syntax
- Verify variable has a current value
- Check for hidden or disabled variables
- Review variable scope and permissions
Incorrect Format
- Use correct format for data source type
- Check multi-value variable formatting
- Verify escape characters in regex
Performance Issues
- Reduce variable query complexity
- Limit number of chained variables
- Decrease auto-refresh frequency
- Use constant variables for static data
Next Steps
Variables
Learn about all variable types and configuration
Creating Dashboards
Build dashboards using templates
Panels
Apply templates in panel queries
Sharing
Share templated dashboards