fixes to template function

- fix 'listification' by partially reverting a change to how terms are passed (noted in #9622)
- added missing parameters to recursive calls to function to keep calls consistent
- replaced var named vars (reserved python) for templatevars