Better way of renderTemplate function.