From 4d472c20f75a5d8c87c226abf7b3268a4e1a56cc Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 23 Jan 2015 12:03:06 +0100 Subject: [PATCH 1/2] Added a reference about including JS and CSS files in PHP templates --- book/templating.rst | 81 +++++++++++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 24 deletions(-) diff --git a/book/templating.rst b/book/templating.rst index 4b003e8bad6..c80437954ba 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 +.. code-configuration:: - {# 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 +.. code-configuration:: - {# app/Resources/views/Contact/contact.html.twig #} - {% extends 'base.html.twig' %} + .. code-block:: html+jinja - {% block stylesheets %} - {{ parent() }} + {# app/Resources/views/Contact/contact.html.twig #} + {% extends 'base.html.twig' %} - - {% endblock %} + {% block stylesheets %} + {{ parent() }} - {# ... #} + + {% endblock %} + + {# ... #} + + .. code-block:: php + + // 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 From 5c6d4b21711d2ef0f42595f326063870378d944e Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 23 Jan 2015 12:05:46 +0100 Subject: [PATCH 2/2] Fixed a minor RST syntax issue --- book/templating.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/book/templating.rst b/book/templating.rst index c80437954ba..3a0c52295c5 100644 --- a/book/templating.rst +++ b/book/templating.rst @@ -1059,7 +1059,7 @@ 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-configuration:: +.. configuration-block:: .. code-block:: html+jinja @@ -1106,7 +1106,7 @@ 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-configuration:: +.. configuration-block:: .. code-block:: html+jinja