Skip to content

Commit de33824

Browse files
ifdatticxabbuh
authored andcommitted
Update templating.rst
| Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.3 | Fixed tickets | Conflicts: book/templating.rst
1 parent 7de02d4 commit de33824

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

book/templating.rst

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Throughout this chapter, template examples will be shown in both Twig and PHP.
135135
web designers everywhere.
136136

137137
Twig can also do things that PHP can't, such as whitespace control,
138-
sandboxing, automatic HTML escaping, manual contextual output escaping,
138+
sandboxing, automatic HTML escaping, manual contextual output escaping,
139139
and the inclusion of custom functions and filters that only affect templates.
140140
Twig contains little features that make writing templates easier and more concise.
141141
Take the following example, which combines a loop with a logical ``if``
@@ -206,8 +206,8 @@ First, build a base layout file:
206206
<div id="sidebar">
207207
{% block sidebar %}
208208
<ul>
209-
<li><a href="/">Home</a></li>
210-
<li><a href="/blog">Blog</a></li>
209+
<li><a href="/">Home</a></li>
210+
<li><a href="/blog">Blog</a></li>
211211
</ul>
212212
{% endblock %}
213213
</div>
@@ -663,7 +663,7 @@ string syntax for controllers (i.e. **bundle**:**controller**:**action**):
663663
{# ... #}
664664
<div id="sidebar">
665665
{{ render(controller(
666-
'AcmeArticleBundle:Article:recentArticles',
666+
'AppBundle:Article:recentArticles',
667667
{ 'max': 3 }
668668
)) }}
669669
</div>
@@ -676,7 +676,7 @@ string syntax for controllers (i.e. **bundle**:**controller**:**action**):
676676
<div id="sidebar">
677677
<?php echo $view['actions']->render(
678678
new \Symfony\Component\HttpKernel\Controller\ControllerReference(
679-
'AcmeArticleBundle:Article:recentArticles',
679+
'AppBundle:Article:recentArticles',
680680
array('max' => 3)
681681
)
682682
) ?>
@@ -745,8 +745,10 @@ tags:
745745
<container xmlns="http://symfony.com/schema/dic/services"
746746
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
747747
xmlns:framework="http://symfony.com/schema/dic/symfony"
748-
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
749-
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
748+
xsi:schemaLocation="http://symfony.com/schema/dic/services
749+
http://symfony.com/schema/dic/services/services-1.0.xsd
750+
http://symfony.com/schema/dic/symfony
751+
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
750752
751753
<!-- ... -->
752754
<framework:config>
@@ -782,8 +784,10 @@ in your application configuration:
782784
<container xmlns="http://symfony.com/schema/dic/services"
783785
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
784786
xmlns:framework="http://symfony.com/schema/dic/symfony"
785-
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
786-
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
787+
xsi:schemaLocation="http://symfony.com/schema/dic/services
788+
http://symfony.com/schema/dic/services/services-1.0.xsd
789+
http://symfony.com/schema/dic/symfony
790+
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
787791
788792
<!-- ... -->
789793
<framework:config>
@@ -796,7 +800,7 @@ in your application configuration:
796800
// app/config/config.php
797801
$container->loadFromExtension('framework', array(
798802
// ...
799-
'templating' => array(
803+
'templating' => array(
800804
'hinclude_default_template' => array(
801805
'hinclude.html.twig',
802806
),
@@ -841,7 +845,7 @@ Or you can also specify a string to display as the default content:
841845
new ControllerReference('...'),
842846
array(
843847
'renderer' => 'hinclude',
844-
'default' => 'Loading...',
848+
'default' => 'Loading...',
845849
)
846850
) ?>
847851
@@ -1014,13 +1018,18 @@ but Symfony provides a more dynamic option via the ``asset`` Twig function:
10141018

10151019
<img src="{{ asset('images/logo.png') }}" alt="Symfony!" />
10161020

1017-
<link href="{{ asset('css/blog.css') }}" rel="stylesheet" type="text/css" />
1021+
<link href="{{ asset('css/blog.css') }}"
1022+
rel="stylesheet"
1023+
type="text/css" />
10181024

10191025
.. code-block:: html+php
10201026

1021-
<img src="<?php echo $view['assets']->getUrl('images/logo.png') ?>" alt="Symfony!" />
1027+
<img src="<?php echo $view['assets']->getUrl('images/logo.png') ?>"
1028+
alt="Symfony!" />
10221029

1023-
<link href="<?php echo $view['assets']->getUrl('css/blog.css') ?>" rel="stylesheet" type="text/css" />
1030+
<link href="<?php echo $view['assets']->getUrl('css/blog.css') ?>"
1031+
rel="stylesheet"
1032+
type="text/css" />
10241033

10251034
The ``asset`` function's main purpose is to make your application more portable.
10261035
If your application lives at the root of your host (e.g. http://example.com),
@@ -1145,7 +1154,8 @@ is by default "web").
11451154

11461155
.. code-block:: html+jinja
11471156

1148-
<link href="{{ asset('bundles/acmedemo/css/contact.css') }}" rel="stylesheet" />
1157+
<link href="{{ asset('bundles/acmedemo/css/contact.css') }}"
1158+
rel="stylesheet" />
11491159

11501160
The end result is a page that includes both the ``main.css`` and ``contact.css``
11511161
stylesheets.
@@ -1239,8 +1249,10 @@ configuration file:
12391249
<container xmlns="http://symfony.com/schema/dic/services"
12401250
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
12411251
xmlns:framework="http://symfony.com/schema/dic/symfony"
1242-
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
1243-
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
1252+
xsi:schemaLocation="http://symfony.com/schema/dic/services
1253+
http://symfony.com/schema/dic/services/services-1.0.xsd
1254+
http://symfony.com/schema/dic/symfony
1255+
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
12441256
12451257
<!-- ... -->
12461258
<framework:config>
@@ -1364,7 +1376,7 @@ One common way to use inheritance is to use a three-level approach. This
13641376
method works perfectly with the three different types of templates that were just
13651377
covered:
13661378

1367-
* Create a ``app/Resources/views/base.html.twig`` file that contains the main
1379+
* Create an ``app/Resources/views/base.html.twig`` file that contains the main
13681380
layout for your application (like in the previous example). Internally, this
13691381
template is called ``base.html.twig``;
13701382

@@ -1455,7 +1467,7 @@ tag to the screen:
14551467

14561468
.. code-block:: html
14571469

1458-
Hello &lt;script&gt;alert(&#39;helloe&#39;)&lt;/script&gt;
1470+
Hello &lt;script&gt;alert(&#39;hello!&#39;)&lt;/script&gt;
14591471

14601472
The Twig and PHP templating systems approach the problem in different ways.
14611473
If you're using Twig, output escaping is on by default and you're protected.
@@ -1497,7 +1509,7 @@ use output escaping, use the special ``escape()`` view method:
14971509
Hello <?php echo $view->escape($name) ?>
14981510

14991511
By default, the ``escape()`` method assumes that the variable is being rendered
1500-
within an HTML context (and thus the variable is escaped to be safe for HTML).
1512+
within a HTML context (and thus the variable is escaped to be safe for HTML).
15011513
The second argument lets you change the context. For example, to output something
15021514
in a JavaScript string, use the ``js`` context:
15031515

0 commit comments

Comments
 (0)