Fabien Potencier 143e4f46f8 feature #2687 Deprecate the possibility to define a block in a non-capturing block from a child template (fabpot)
This PR was merged into the 2.x branch.

Discussion
----------

Deprecate the possibility to define a block in a non-capturing block from a child template

fixes #351, #541, #703, #988, #1639, #1685, #2393

One recurring issue (see the probably non-exhaustive list of issues references above) is a misunderstanding of how blocks work in a child template.

For instance, there is no way to define a `block` conditionally:

```twig
{% extends "layout" %}

{% if ... %}
    {% block content %}
        ...
    {% endblock %}
{% endif %}
```

And wrapping a `block` definition with a `spaceless` tag does not work:

```twig
{% extends "layout" %}

{% spaceless %}
    {% block content %}
        ...
    {% endblock %}
{% endspaceless %}
```

The issue is that the above templates compile just fine, but not in a way people expect. Basically, the condition would be empty.

Interestingly enough, wrapping a `block` definition might be useful/work as expected when used with "capturing" tags like `set`:

```twig
{% extends "layout" %}

{% set content %}
    {% block content %}
        ...
    {% endblock %}
{% endset %}
```

Not sure if that's useful, but here, the `block` tag will serve as the blog definition AND it will also be displayed in place. I would not recommend such usages.

This pull request deprecates the cases where the compiled template would never reflect the developer intent, but keeps the "working" scenarii as is.

I've been trying to fix that issue for **years**. Very happy to have found a simple solution without breaking anything that worked fine.

Commits
-------

9b938887 deprecated the possibility to define a block in a non-capturing block from a child template
2018-05-18 12:15:51 +02:00
2018-01-30 14:02:48 +01:00
2017-06-12 09:59:07 -07:00
2018-05-18 09:34:00 +02:00
2018-01-07 18:54:25 +01:00
2018-04-20 07:23:43 +02:00

Twig, the flexible, fast, and secure template language for PHP
==============================================================

Twig is a template language for PHP, released under the new BSD license (code
and documentation).

Twig uses a syntax similar to the Django and Jinja template languages which
inspired the Twig runtime environment.

More Information
----------------

Read the `documentation`_ for more information.

.. _documentation: https://twig.symfony.com/documentation
Languages
PHP 99.9%