How to get the current value of a template variable via Javascript?

See How to read a template variable from a plugin (PanelCtrl)? for an example of our to get the actual template varialbe