add middleware and modify all templates