Make the legacy editor more robust against invalid templates.

Fixes #6812.