Externalize the template rendering function