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