Support nested blocks in templates (see #6934)