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