factor Template logic from View