template inversion