Move template related logic from view to template