8000 Reworded the explanation · symfony/symfony-docs@f7e1419 · GitHub
[go: up one dir, main page]

Skip to content

Commit f7e1419

Browse files
committed
Reworded the explanation
1 parent 2964733 commit f7e1419

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

templating.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,6 @@ template living inside the AcmeBlogBundle, for example, can be overridden
365365
by placing a template of the same name in the ``app/Resources/AcmeBlogBundle/views/``
366366
directory. This gives the power to override templates from any vendor bundle.
367367

368-
If you have overridden a template, you can use the "!" prefix to refer to the original bundle's
369-
template. E.g. ``@!AcmeBlog/layout.html.twig``
370-
371368
Template Suffix
372369
~~~~~~~~~~~~~~~
373370

templating/overriding.rst

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,25 @@ from the bundle to ``app/Resources/AcmeBlogBundle/views/Blog/index.html.twig``
1919
(the ``app/Resources/AcmeBlogBundle`` directory won't exist, so you'll need
2020
to create it). You're now free to customize the template.
2121

22+
Instead of overriding an entire template, you may just want to override one or
23+
more blocks. However, since you are overriding the template you want to extend
24+
from, you would end up in an infinite loop error. The solution is to use the
25+
special ``!`` prefix in the template name to tell Symfony that you want to
26+
extend from the original template, not from the overridden one:
27+
28+
.. code-block:: twig
29+
30+
{# app/Resources/AcmeBlogBundle/views/Blog/index.html.twig #}
31+
32+
{# the special '!' prefix avoids errors when extending from an overridden template #}
33+
{% extends "@!AcmeBlogBundle/index.html.twig" %}
34+
35+
{% block some_block %}
36+
...
37+
{% endblock %}
38+
2239
.. versionadded:: 3.4
23-
24-
Instead of overridding an entire template, you may just want to override one or more blocks. You can do that by extending the original
25-
template using the "!" prefix. For example:
26-
``{% extends "@!AcmeBlogBundle/layout.html.twig" %}``
40+
The special ``!`` template prefix was introduced in Symfony 3.4.
2741

2842
.. caution::
2943

0 commit comments

Comments
 (0)
0