builds a javascript variable from a template.