updating template to encode all variables

* moving template load to top of body