Begin Template logic