We present an empirical model for the number of globular clusters (GCs) in galaxies based on recent data showing a tight relationship between dark matter halo virial masses and GC numbers. While a simple base model forming GCs in low-mass haloes reproduces this relation, we show that a second formation pathway for GCs is needed to account for observed younger GC populations. We confirm previous works that reported the observed linear correlation as being a consequence of hierarchical merging and its insensitivity to the exact GC formation processes at higher virial masses, even for a dual formation scenario. We find that the scatter of the linear relation is strongly correlated with the relative amount of smooth accretion: the more dark matter is smoothly accreted, the fewer GCs a halo has compared to other haloes of the same mass. This scatter is smaller than that introduced by halo mass measurements, indicating that the number of GCs in a galaxy is a good tracer for its dark matter mass. Smooth accretion is also the reason for a lower average dark matter mass per GC in low-mass haloes. Finally, we successfully reproduce the observed general trend of GCs being old and the tendency of more massive haloes hosting older GC systems. Including the second GC formation mechanism through gas-rich mergers leads to a more realistic variety of GC age distributions and also introduces an age inversion in the halo virial mass range $log M_mathrm{vir}/mathrm{M}_odot = 11{-}13$.