@@ -148,8 +148,8 @@ Twig Template Caching
148
148
Twig is fast because each template is compiled to a native PHP class and cached.
149
149
But don't worry: this happens automatically and doesn't require *you * to do anything.
150
150
And while you're developing, Twig is smart enough to re-compile your templates after
151
- you make any changes. That means Twig is fast in production, but easy to use while
152
- developing.
151
+ you make any changes. That means Twig is fast in production, but convenient to use
152
+ while developing.
153
153
154
154
.. index ::
155
155
single: Templating; Inheritance
@@ -200,12 +200,12 @@ First, build a base layout file:
200
200
Though the discussion about template inheritance will be in terms of Twig,
201
201
the philosophy is the same between Twig and PHP templates.
202
202
203
- This template defines the base HTML skeleton document of a simple two-column
203
+ This template defines the base HTML skeleton document of a two-column
204
204
page. In this example, three ``{% block %} `` areas are defined (``title ``,
205
205
``sidebar `` and ``body ``). Each block may be overridden by a child template
206
206
or left with its default implementation. This template could also be rendered
207
207
directly. In that case the ``title ``, ``sidebar `` and ``body `` blocks would
208
- simply retain the default values used in this template.
208
+ retain the default values used in this template.
209
209
210
210
A child template might look like this:
211
211
@@ -226,7 +226,7 @@ A child template might look like this:
226
226
.. note ::
227
227
228
228
The parent template is stored in ``templates/ ``, so its path is
229
- simply ``base.html.twig ``. The template naming conventions are explained
229
+ ``base.html.twig ``. The template naming conventions are explained
230
230
fully in :ref: `template-naming-locations `.
231
231
232
232
The key to template inheritance is the ``{% extends %} `` tag. This tells
@@ -437,7 +437,8 @@ template. First, create the template that you'll need to reuse.
437
437
{{ article.body }}
438
438
</p>
439
439
440
- Including this template from any other template is simple:
440
+ Including this template from any other template is achieved with the
441
+ ``{{ include() }} `` function:
441
442
442
443
.. code-block :: html+twig
443
444
@@ -452,12 +453,11 @@ Including this template from any other template is simple:
452
453
{% endfor %}
453
454
{% endblock %}
454
455
455
- The template is included using the ``{{ include() }} `` function. Notice that the
456
- template name follows the same typical convention. The ``article_details.html.twig ``
457
- template uses an ``article `` variable, which we pass to it. In this case,
458
- you could avoid doing this entirely, as all of the variables available in
459
- ``list.html.twig `` are also available in ``article_details.html.twig `` (unless
460
- you set `with_context `_ to false).
456
+ Notice that the template name follows the same typical convention. The
457
+ ``article_details.html.twig `` template uses an ``article `` variable, which we
458
+ pass to it. In this case, you could avoid doing this entirely, as all of the
459
+ variables available in ``list.html.twig `` are also available in
460
+ ``article_details.html.twig `` (unless you set `with_context `_ to false).
461
461
462
462
.. tip ::
463
463
@@ -537,7 +537,7 @@ configuration:
537
537
538
538
return $routes;
539
539
540
- To link to the page, just use the ``path() `` Twig function and refer to the route:
540
+ To link to the page, use the ``path() `` Twig function and refer to the route:
541
541
542
542
.. code-block :: html+twig
543
543
@@ -631,7 +631,7 @@ Linking to Assets
631
631
~~~~~~~~~~~~~~~~~
632
632
633
633
Templates also commonly refer to images, JavaScript, stylesheets and other
634
- assets. Of course you could hard-code the path to these assets (e.g. ``/images/logo.png ``),
634
+ assets. You could hard-code the web path to these assets (e.g. ``/images/logo.png ``),
635
635
but Symfony provides a more dynamic option via the ``asset() `` Twig function.
636
636
637
637
To use this function, install the *asset * package:
@@ -715,8 +715,9 @@ stylesheets and JavaScripts that you'll need throughout your site:
715
715
</body>
716
716
</html>
717
717
718
- That's easy enough! But what if you need to include an extra stylesheet or
719
- JavaScript from a child template? For example, suppose you have a contact
718
+ This looks almost like regular HTML, but with the addition of the
719
+ ``{% block %} ``. Those are useful when you need to include an extra stylesheet
720
+ or JavaScript from a child template. For example, suppose you have a contact
720
721
page and you need to include a ``contact.css `` stylesheet *just * on that
721
722
page. From inside that contact page's template, do the following:
722
723
@@ -733,11 +734,11 @@ page. From inside that contact page's template, do the following:
733
734
734
735
{# ... #}
735
736
736
- In the child template, you simply override the ``stylesheets `` block and
737
- put your new stylesheet tag inside of that block. Of course, since you want
738
- to add to the parent block's content (and not actually *replace * it), you
739
- should use the `` parent() `` Twig function to include everything from the ``stylesheets ``
740
- block of the base template.
737
+ In the child template, you override the ``stylesheets `` block and put your new
738
+ stylesheet tag inside of that block. Since you want to add to the parent
739
+ block's content (and not actually *replace * it), you also use the `` parent() ``
740
+ Twig function to include everything from the ``stylesheets `` block of the base
741
+ template.
741
742
742
743
You can also include assets located in your bundles' ``Resources/public/ `` folder.
743
744
You will need to run the ``php bin/console assets:install target [--symlink] ``
0 commit comments