move logic from template to provider