Add a context manager to avoid ugly template pollution.

Signed-off-by: Chris Lamb <chris@chris-lamb.co.uk>