Remove code duplication in view helper