Skip to content

Commit 31791c9

Browse files
javiereguiluzweaverryan
authored andcommitted
Removed a short article about overriding bundle templates
1 parent 5925dbc commit 31791c9

File tree

5 files changed

+30
-53
lines changed

5 files changed

+30
-53
lines changed

_build/redirection_map

+1
Original file line numberDiff line numberDiff line change
@@ -388,3 +388,4 @@
388388
/quick_tour/the_controller /quick_tour/the_big_picture
389389
/quick_tour/the_view /quick_tour/flex_recipes
390390
/service_container/service_locators /service_container/service_subscribers_locators
391+
/templating/overriding /bundles/override

bundles/override.rst

+24-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,33 @@ features of a bundle.
1616
and call the :ref:`locateResource() method <http-kernel-resource-locator>`
1717
to turn them into physical paths when needed.
1818

19+
.. _override-templates:
20+
1921
Templates
2022
---------
2123

22-
See :doc:`/templating/overriding`.
24+
Third-party bundle templates can be overridden in the
25+
``<your-project>/templates/bundles/<bundle-name>/`` directory. The new templates
26+
must use the same name and path (relative to ``<bundle>/Resources/views/``) as
27+
the original templates.
28+
29+
For example, to override the ``Resources/views/Registration/confirmed.html.twig``
30+
template from the FOSUserBundle, create this template:
31+
``<your-project>/templates/bundles/FOSUserBundle/Registration/confirmed.html.twig``
32+
33+
.. caution::
34+
35+
If you add a template in a new location, you *may* need to clear your
36+
cache (``php bin/console cache:clear``), even if you are in debug mode.
37+
38+
.. _templating-overriding-core-templates:
39+
40+
.. tip::
41+
42+
Symfony internals use some bundles too, so you can apply the same technique
43+
to override the core Symfony templates. For example, you can
44+
:doc:`customize error pages </controller/error_pages>` overriding TwigBundle
45+
templates.
2346

2447
Routing
2548
-------

controller/error_pages.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ logic to determine the template filename:
6565

6666
.. _overriding-or-adding-templates:
6767

68-
To override these templates, simply rely on the standard Symfony method for
69-
:doc:`overriding templates that live inside a bundle </templating/overriding>`:
68+
To override these templates, rely on the standard Symfony method for
69+
:ref:`overriding templates that live inside a bundle <override-templates>` and
7070
put them in the ``templates/bundles/TwigBundle/Exception/`` directory.
7171

7272
A typical project that returns HTML and JSON pages, might look like this:

templating.rst

+3-6
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,7 @@ By default, templates can live in two different locations:
360360
``templates/``
361361
The application's ``views`` directory can contain application-wide base templates
362362
(i.e. your application's layouts and templates of the application bundle) as
363-
well as templates that override third party bundle templates
364-
(see :doc:`/templating/overriding`).
363+
well as templates that :ref:`override third party bundle templates <override-templates>`.
365364

366365
``vendor/path/to/CoolBundle/Resources/views/``
367366
Each third party bundle houses its templates in its ``Resources/views/``
@@ -405,10 +404,8 @@ for several types of templates, each which lives in a specific location:
405404
is missing (e.g. ``Blog``), the template lives at
406405
``Resources/views/layout.html.twig`` inside AcmeBlogBundle.
407406

408-
In the :doc:`/templating/overriding` section, you'll find out how each
409-
template living inside the AcmeBlogBundle, for example, can be overridden
410-
by placing a template of the same name in the ``templates/bundles/AcmeBlogBundle/``
411-
directory. This gives the power to override templates from any vendor bundle.
407+
Using this namespaced syntax instead of the real file paths allows applications
408+
to :ref:`override templates that live inside any bundle <override-templates>`.
412409

413410
Template Suffix
414411
~~~~~~~~~~~~~~~

templating/overriding.rst

-44
This file was deleted.

0 commit comments

Comments
 (0)