@@ -118,6 +118,76 @@ TwigBundle Configuration ("twig")
118
118
Configuration
119
119
-------------
120
120
121
+ auto_reload
122
+ ~~~~~~~~~~~
123
+
124
+ **type **: ``boolean `` **default **: ``'%kernel.debug%' ``
125
+
126
+ If ``true ``, whenever a template is rendered, Symfony checks first if its source
127
+ code has changed since it was compiled. If it has changed, the template is
128
+ compiled again automatically.
129
+
130
+ autoescape_service
131
+ ~~~~~~~~~~~~~~~~~~
132
+
133
+ **type **: ``string `` **default **: ``null ``
134
+
135
+ As of Twig 1.17, the escaping strategy applied by default to the template is
136
+ determined during compilation time based on the filename of the template. This
137
+ means for example that the contents of a ``*.html.twig `` template are escaped
138
+ for HTML and the contents of ``*.js.twig `` are escaped for JavaScript.
139
+
140
+ This option allows to define the Symfony service which will be used to determine
141
+ the default escaping applied to the template.
142
+
143
+ autoescape_service_method
144
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
145
+
146
+ **type **: ``string `` **default **: ``null ``
147
+
148
+ If ``autoescape_service `` option is defined, then this option defines the method
149
+ called to determine the default escaping applied to the template.
150
+
151
+ base_template_class
152
+ ~~~~~~~~~~~~~~~~~~~
153
+
154
+ **type **: ``string `` **default **: ``'Twig_Template' ``
155
+
156
+ Twig templates are compiled into PHP classes before using them to render
157
+ contents. This option defines the base class from which all the template classes
158
+ extend. Using a custom base template is discouraged because it will make your
159
+ application harder to maintain.
160
+
161
+ cache
162
+ ~~~~~
163
+
164
+ **type **: ``string `` **default **: ``'%kernel.cache_dir%/twig' ``
165
+
166
+ Before using the Twig templates to render some contents, they are compiled into
167
+ regular PHP code. Compilation is a costly process, so the result is cached in
168
+ the directory defined by this configuration option.
169
+
170
+ Set this option to ``null `` to disable Twig template compilation. However, this
171
+ is not recommended; not even in the ``dev `` environment, because the
172
+ ``auto_reload `` option ensures that cached templates which have changed get
173
+ compiled again.
174
+
175
+ charset
176
+ ~~~~~~~
177
+
178
+ **type **: ``string `` **default **: ``'%kernel.charset%' ``
179
+
180
+ The charset used by the template files. In the Symfony Standard edition this
181
+ defaults to the ``UTF-8 `` charset.
182
+
183
+ debug
184
+ ~~~~~
185
+
186
+ **type **: ``boolean `` **default **: ``'%kernel.debug%' ``
187
+
188
+ If ``true ``, the compiled templates include a ``__toString() `` method that can
189
+ be used to display their nodes.
190
+
121
191
.. _config-twig-exception-controller :
122
192
123
193
exception_controller
@@ -133,3 +203,128 @@ conditions (see :doc:`/cookbook/controller/error_pages`). Modifying this
133
203
option is advanced. If you need to customize an error page you should use
134
204
the previous link. If you need to perform some behavior on an exception,
135
205
you should add a listener to the ``kernel.exception `` event (see :ref: `dic-tags-kernel-event-listener `).
206
+
207
+ optimizations
208
+ ~~~~~~~~~~~~~
209
+
210
+ **type **: ``int `` **default **: ``-1 ``
211
+
212
+ Twig includes an extension called ``optimizer `` which is enabled by default in
213
+ Symfony applications. This extension analyzes the templates to optimize them
214
+ when being compiled. For example, if your template doesn't use the special
215
+ ``loop `` variable inside a ``for `` tag, this extension removes the initialization
216
+ of that unused variable.
217
+
218
+ By default, this option is ``-1 ``, which means that all optimizations are turned
219
+ on. Set it to ``0 `` to disable all the optimizations. You can even enable or
220
+ disable these optimizations selectively, as explained in the Twig documentation
221
+ about `the optimizer extension `_.
222
+
223
+ paths
224
+ ~~~~~
225
+
226
+ **type **: ``array `` **default **: ``null ``
227
+
228
+ This option defines the directories where Symfony will look for Twig templates
229
+ in addition to the default locations (``app/Resources/views/ `` and the bundles'
230
+ ``Resources/views/ `` directories). This is useful to integrate the templates
231
+ included in some library or package used by your application.
232
+
233
+ The values of the ``paths `` option are defined as ``key: value `` pairs where the
234
+ ``value `` part can be ``null ``. For example:
235
+
236
+ .. configuration-block ::
237
+
238
+ .. code-block :: yaml
239
+
240
+ # app/config/config.yml
241
+ twig :
242
+ # ...
243
+ paths :
244
+ ' %kernel.root_dir%/../vendor/acme/foo-bar/templates ' : ~
245
+
246
+ .. code-block :: xml
247
+
248
+ <!-- app/config/config.xml -->
249
+ <container xmlns =" http://symfony.com/schema/dic/services"
250
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
251
+ xmlns : twig =" http://symfony.com/schema/dic/twig"
252
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
253
+ http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd" >
254
+
255
+ <twig : config >
256
+ <!-- ... -->
257
+ <twig : path >%kernel.root_dir%/../vendor/acme/foo-bar/templates</twig : path >
258
+ </twig : config >
259
+ </container >
260
+
261
+ .. code-block :: php
262
+
263
+ // app/config/config.php
264
+ $container->loadFromExtension('twig', array(
265
+ // ...
266
+ 'paths' => array(
267
+ '%kernel.root_dir%/../vendor/acme/foo-bar/templates' => null,
268
+ ),
269
+ ));
270
+
271
+ The directories defined in the ``paths `` option have more priority than the
272
+ default directories defined by Symfony. In the above example, if the template
273
+ exists in the ``acme/foo-bar/templates/ `` directory inside your application's
274
+ ``vendor/ ``, it will be used by Symfony.
275
+
276
+ If you provide a value for any path, Symfony will consider it the Twig namespace
277
+ for that directory:
278
+
279
+ .. configuration-block ::
280
+
281
+ .. code-block :: yaml
282
+
283
+ # app/config/config.yml
284
+ twig :
285
+ # ...
286
+ paths :
287
+ ' %kernel.root_dir%/../vendor/acme/foo-bar/templates ' : ' foo_bar'
288
+
289
+ .. code-block :: xml
290
+
291
+ <!-- app/config/config.xml -->
292
+ <container xmlns =" http://symfony.com/schema/dic/services"
293
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
294
+ xmlns : twig =" http://symfony.com/schema/dic/twig"
295
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
296
+ http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd" >
297
+
298
+ <twig : config >
299
+ <!-- ... -->
300
+ <twig : path namespace =" foo_bar" >%kernel.root_dir%/../vendor/acme/foo-bar/templates</twig : path >
301
+ </twig : config >
302
+ </container >
303
+
304
+ .. code-block :: php
305
+
306
+ # app/config/config.php
307
+ $container->loadFromExtension('twig', array(
308
+ // ...
309
+ 'paths' => array(
310
+ '%kernel.root_dir%/../vendor/acme/foo-bar/templates' => 'foo_bar',
311
+ ),
312
+ ));
313
+
314
+ This option is useful to not mess with the default template directories defined
315
+ by Symfony. Besides, it simplifies how you refer to those templates:
316
+
317
+ .. code-block :: text
318
+
319
+ @foo_bar/template_name.html.twig
320
+
321
+ strict_variables
322
+ ~~~~~~~~~~~~~~~~
323
+
324
+ **type **: ``boolean `` **default **: ``'%kernel.debug%' ``
325
+
326
+ If set to ``true ``, Symfony shows an exception whenever a Twig variable,
327
+ attribute or method doesn't exist. If set to ``false `` these errors are ignored
328
+ and the non-existing values are replaced by ``null ``.
329
+
330
+ .. _`the optimizer extension` : http://twig.sensiolabs.org/doc/api.html#optimizer-extension
0 commit comments