Moving template_id assignment into result