@@ -135,7 +135,7 @@ Throughout this chapter, template examples will be shown in both Twig and PHP.
135
135
web designers everywhere.
136
136
137
137
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,
139
139
and the inclusion of custom functions and filters that only affect templates.
140
140
Twig contains little features that make writing templates easier and more concise.
141
141
Take the following example, which combines a loop with a logical ``if ``
@@ -206,8 +206,8 @@ First, build a base layout file:
206
206
<div id="sidebar">
207
207
{% block sidebar %}
208
208
<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>
211
211
</ul>
212
212
{% endblock %}
213
213
</div>
@@ -663,7 +663,7 @@ string syntax for controllers (i.e. **bundle**:**controller**:**action**):
663
663
{# ... #}
664
664
<div id="sidebar">
665
665
{{ render(controller(
666
- 'AcmeArticleBundle :Article: recentArticles',
666
+ 'AppBundle :Article: recentArticles',
667
667
{ 'max': 3 }
668
668
)) }}
669
669
</div>
@@ -676,7 +676,7 @@ string syntax for controllers (i.e. **bundle**:**controller**:**action**):
676
676
<div id="sidebar">
677
677
<?php echo $view['actions']->render(
678
678
new \S ymfony\C omponent\H ttpKernel\C ontroller\C ontrollerReference(
679
- 'AcmeArticleBundle :Article: recentArticles',
679
+ 'AppBundle :Article: recentArticles',
680
680
array('max' => 3)
681
681
)
682
682
) ?>
@@ -745,8 +745,10 @@ tags:
745
745
<container xmlns =" http://symfony.com/schema/dic/services"
746
746
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
747
747
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" >
750
752
751
753
<!-- ... -->
752
754
<framework : config >
@@ -782,8 +784,10 @@ in your application configuration:
782
784
<container xmlns =" http://symfony.com/schema/dic/services"
783
785
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
784
786
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" >
787
791
788
792
<!-- ... -->
789
793
<framework : config >
@@ -796,7 +800,7 @@ in your application configuration:
796
800
// app/config/config.php
797
801
$container->loadFromExtension('framework', array(
798
802
// ...
799
- 'templating' => array(
803
+ 'templating' => array(
800
804
'hinclude_default_template' => array(
801
805
'hinclude.html.twig',
802
806
),
@@ -841,7 +845,7 @@ Or you can also specify a string to display as the default content:
841
845
new ControllerReference('...'),
842
846
array(
843
847
'renderer' => 'hinclude',
844
- 'default' => 'Loading...',
848
+ 'default' => 'Loading...',
845
849
)
846
850
) ?>
847
851
@@ -1014,13 +1018,18 @@ but Symfony provides a more dynamic option via the ``asset`` Twig function:
1014
1018
1015
1019
<img src="{{ asset('images/logo.png') }}" alt="Symfony!" />
1016
1020
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" />
1018
1024
1019
1025
.. code-block :: html+php
1020
1026
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!" />
1022
1029
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" />
1024
1033
1025
1034
The ``asset `` function's main purpose is to make your application more portable.
1026
1035
If your application lives at the root of your host (e.g. http://example.com),
@@ -1145,7 +1154,8 @@ is by default "web").
1145
1154
1146
1155
.. code-block :: html+jinja
1147
1156
1148
- <link href="{{ asset('bundles/acmedemo/css/contact.css') }}" rel="stylesheet" />
1157
+ <link href="{{ asset('bundles/acmedemo/css/contact.css') }}"
1158
+ rel="stylesheet" />
1149
1159
1150
1160
The end result is a page that includes both the ``main.css `` and ``contact.css ``
1151
1161
stylesheets.
@@ -1239,8 +1249,10 @@ configuration file:
1239
1249
<container xmlns =" http://symfony.com/schema/dic/services"
1240
1250
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
1241
1251
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" >
1244
1256
1245
1257
<!-- ... -->
1246
1258
<framework : config >
@@ -1364,7 +1376,7 @@ One common way to use inheritance is to use a three-level approach. This
1364
1376
method works perfectly with the three different types of templates that were just
1365
1377
covered:
1366
1378
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
1368
1380
layout for your application (like in the previous example). Internally, this
1369
1381
template is called ``base.html.twig ``;
1370
1382
@@ -1455,7 +1467,7 @@ tag to the screen:
1455
1467
1456
1468
.. code-block :: html
1457
1469
1458
- Hello < ; script> ; alert(' ; helloe ' ; )< ; /script> ;
1470
+ Hello < ; script> ; alert(' ; hello! ' ; )< ; /script> ;
1459
1471
1460
1472
The Twig and PHP templating systems approach the problem in different ways.
1461
1473
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:
1497
1509
Hello <?php echo $view->escape($name) ?>
1498
1510
1499
1511
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).
1501
1513
The second argument lets you change the context. For example, to output something
1502
1514
in a JavaScript string, use the ``js `` context:
1503
1515
0 commit comments