How to read a template variable from a plugin (PanelCtrl)?


I am writing a plugin (panel). I would like to get the value of a template variable from my plugin code but I can’t figure out how to do it.

I started my plugin modifying the “Clock Panel Plugin” tutorial, here .

I need to be able to read the template variable from Javascript, inside the “updateClock()” function. Is this possible ?


use templateSrv, and templateSrv.replace to interpolate a string

1 Like

thank yo torkel,

I found the way, i write here for others who may need it:

1] put this into the contructor
this.templateSrv = $injector.get('templateSrv');

2] put something like this into the updateContent() [ keeping the
tutorial structure] . Consider I called my variable “lquery”. The
“try” is necessary.

try {
	 var templateSrv = this.templateSrv;
	 var v1 = templateSrv.replace('$lquery');
	 console.log("v1: " + v1);
  } catch (err) {
	 console.log("error: " + err);
1 Like