initial implementation of tmpl (currently still a little hacky)