Update template.js

Add more methods, add general functions, add special character escaping and interpolation