Import Grafana variable into JavaScript

Hi all!
I am new user inf grafana. We are using Grafana v4.6.2. I already created my dashboard with template.
I have variable in template, where through drop menu users can select site name and after that users have all graphs related to this site (link utilization, sla statistics and so on). Successfully did it.
Here are thing that I want to do now:
I created new row and selected TEXT panel with html. With javascript help I want to create tool, which will be generated according to site. To do this, I need to somehow import my Grafana template variable value to javascript so then I can create code which will generate tool according to this site value, which user choose.
Any ideas how I can do it? (if possible) Didn’t find any information how to do it yet.
Thank in advance!


I’m a bit unsure, but have you tried reference a template variable in your html/javascript? Like this

<script type="text/javascript">
var test = '$variable';

Seems to work when I test.


Thanks for reply! I will test this!

Works! Didn’t think that would be so easy, thanks!

I’m also starting in Grafana (and mainly is SQL), in the same idea, is that possible to use the “variable/function” __timeTo() or __timeFrom() in the JavaScript ?
With Grafana 6.3.6.

Thanks in advance

Edit : Sorry for this useless post… solution is here :