diff --git a/book/templating.rst b/book/templating.rst index 0e00d61581f..b185e909017 100644 --- a/book/templating.rst +++ b/book/templating.rst @@ -1059,43 +1059,76 @@ one called ``stylesheets`` inside the ``head`` tag and another called ``javascri just above the closing ``body`` tag. These blocks will contain all of the stylesheets and JavaScripts that you'll need throughout your site: -.. code-block:: html+jinja +.. configuration-block:: - {# app/Resources/views/base.html.twig #} - -
- {# ... #} + .. code-block:: html+jinja - {% block stylesheets %} - - {% endblock %} - - - {# ... #} + {# app/Resources/views/base.html.twig #} + + + {# ... #} - {% block javascripts %} - - {% endblock %} - - + {% block stylesheets %} + + {% endblock %} + + + {# ... #} + + {% block javascripts %} + + {% endblock %} + + + + .. code-block:: php + + // app/Resources/views/base.html.php + + + + + start('stylesheets') ?> + + stop() ?> + + + + + start('javascripts') ?> + + stop() ?> + + That's easy enough! But what if you need to include an extra stylesheet or JavaScript from a child template? For example, suppose you have a contact page and you need to include a ``contact.css`` stylesheet *just* on that page. From inside that contact page's template, do the following: -.. code-block:: html+jinja +.. configuration-block:: + + .. code-block:: html+jinja + + {# app/Resources/views/Contact/contact.html.twig #} + {% extends 'base.html.twig' %} + + {% block stylesheets %} + {{ parent() }} + + + {% endblock %} - {# app/Resources/views/Contact/contact.html.twig #} - {% extends 'base.html.twig' %} + {# ... #} - {% block stylesheets %} - {{ parent() }} + .. code-block:: php - - {% endblock %} + // app/Resources/views/Contact/contact.html.twig + extend('base.html.php') ?> - {# ... #} + start('stylesheets') ?> + + stop() ?> In the child template, you simply override the ``stylesheets`` block and put your new stylesheet tag inside of that block. Of course, since you want