Tweaking error message resulting from undefined template variables

Fixes #5114