Fix template escape processing. Fixes #752.