Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f7e1419

Browse filesBrowse files
committed
Reworded the explanation
1 parent 2964733 commit f7e1419
Copy full SHA for f7e1419

File tree

Expand file treeCollapse file tree

2 files changed

+18
-7
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-7
lines changed

‎templating.rst

Copy file name to clipboardExpand all lines: templating.rst
-3Lines 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

Copy file name to clipboardExpand all lines: templating/overriding.rst
+18-4Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.