Remove duplicate code for attachTemplateVars.