grafana / grafana-plugin-examples

189 stars 53 forks source link

Example: how to support template variabels in panels #160

Open mckn opened 1 year ago

mckn commented 1 year ago

When building a panel you should use the replaceVariables function instead of using the templateSrv directly. The main reason for this is to get proper support for template variabels when repeating the panel based on a template variable.

We should add an example show casing this along side of documentation highlighting what additional scenarios the panel will support by using this function.

For more information see the following PR and issue.

https://github.com/grafana/grafana-iot-twinmaker-app/pull/188

sympatheticmoose commented 1 year ago

@mckn iirc 2 of our examples use replaceVariables, 1 uses templateSrv. Is this just to update the one which uses templateSrv or are there other changes we should make.

In terms of documentation, again it would be good to expand upon where you're thinking for this and where a user would have first thought to use templateSrv as that user journey is unclear to me at this point

mckn commented 1 year ago

@mckn iirc 2 of our examples use replaceVariables, 1 uses templateSrv. Is this just to update the one which uses templateSrv or are there other changes we should make.

In terms of documentation, again it would be good to expand upon where you're thinking for this and where a user would have first thought to use templateSrv as that user journey is unclear to me at this point

Yupp, agree about the docs! The example using templateSrv is a data source and in that context it should be ok to use the templateSrv.