generalize template handler