Document the use of Templating
See original GitHub issueWhat you expected to happen?
I attempted to use add templating to a dashboard, it is not documented how to use it so I provided these parameters: https://github.com/aknuds1/grafanalib/blob/master/grafanalib/core.py#L431-L439
:param default: the default value for the variable
:param dataSource: where to fetch the values for the variable from
:param label: the variable's human label
:param name: the variable's name
:param query: the query users to fetch the valid values of the variable
:param allValue: specify a custom all value with regex,
globs or lucene syntax.
:param includeAll: Add a special All option whose value includes
all options.
What happened?
Js error in grafana when trying to import the resulting json dashboard. After some effort I determined that the js error is caued by the absence of some of these values for each template: https://github.com/aknuds1/grafanalib/blob/master/grafanalib/core.py#L456-L470
def to_json_data(self):
return {**_as_dict(self), **{
'current': {
'text': self.default,
'value': self.default,
'tags': [],
},
'hide': 0,
'multi': False,
'options': [],
'refresh': 1,
'regex': '',
'sort': 1,
'tagValuesQuery': None,
'tagsQuery': None,
'type': 'query',
}}
I’m not very familiar with python but that bit of code looks like it should be used as defaults? In any case, when I include those keys/values for each templated variable in my dashboard.py, the resulting json generated does work!
How to reproduce it?
Create any dashboard that uses the templating, i.e.:
templating=Templating(list=[
{ # namespace
"default": "",
"datasource": "prometheus",
"label": "Namespace",
"name": "namespace",
"query": "label_values(kube_pod_info, namespace)",
"allValue": ".+",
"includeAll": True,
},
]),
Is this a bug with how templating gets rendered? If not, can you add the proper incantation to use templating in the example dashboard.py?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:8 (3 by maintainers)

Top Related StackOverflow Question
I’m still checking this out - but I think I’ve found the problem, in my experimentation, it looks like ‘selected’ has to be set to either True or False to get things working https://github.com/chrisfleming/grafanalib/commit/0589cb5e67084e9c63669514d3efa267b44cbcc4
I’ve a few more checks but should have a pull request next week.
Could templating still be improved with some better docs? Or do we think this issue can be closed?