Unify template code front and back