Consolidated template rendering code