Error "A block definition cannot be nested under non-capturing nodes" not emitted when there is no parent

Open
#3,926 27 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
php
Domain
backend

Research direction

Reproduce both Twig templates and trace how block definitions nested under non-capturing nodes are validated, comparing the case with and without the extends statement. Determine why the two templates differ, then make their behavior consistent and add a regression test covering both cases.

Written by the indexing model from the issue text.

Description

Investigate before 4.x

When rendering the following template, I get the error A block definition cannot be nested under non-capturing nodes:

{% extends "layout.twig" %}

{% if false %}
    {% block content %}FOO{% endblock %}
{% endif %}

(note that there is no need for the layout.twig template to exist for the error to be thrown)

But when rendering the following one, I don't get any error:

{% if false %}
    {% block content %}FOO{% endblock %}
{% endif %}

In both cases, there is a block definition nested under a non-capturing node (if), so why is the first template failing and why is the second one not failing?

Dominant language
PHP
Stars
8.4k
Forks
1.3k
Avg merge
1d 13h
Merged PRs (30d)
37

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from twigphp/Twig

All issues in twigphp/Twig

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.