Skip to content

Commit 0a25c17

Browse files
committed
Added docs for "date" and "number_format" Twig options
1 parent ecde568 commit 0a25c17

File tree

1 file changed

+100
-17
lines changed

1 file changed

+100
-17
lines changed

reference/configuration/twig.rst

Lines changed: 100 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ TwigBundle Configuration ("twig")
5353
paths:
5454
'%kernel.root_dir%/../vendor/acme/foo-bar/templates': foo_bar
5555
56+
# The following were added in Symfony 2.7.
57+
date:
58+
format: d.m.Y, H:i:s
59+
interval_format: '%%d days'
60+
timezone: Asia/Tokyo
61+
number_format:
62+
decimals: 2
63+
decimal_point: ','
64+
thousands_separator: '.'
65+
5666
.. code-block:: xml
5767
5868
<!-- app/config/config.xml -->
@@ -92,23 +102,33 @@ TwigBundle Configuration ("twig")
92102
'form_themes' => array(
93103
'form_div_layout.html.twig', // Default
94104
'MyBundle::form.html.twig',
95-
),
96-
'globals' => array(
97-
'foo' => '@bar',
98-
'pi' => 3.14,
99-
),
100-
'auto_reload' => '%kernel.debug%',
101-
'autoescape' => 'name',
102-
'base_template_class' => 'Twig_Template',
103-
'cache' => '%kernel.cache_dir%/twig',
104-
'charset' => '%kernel.charset%',
105-
'debug' => '%kernel.debug%',
106-
'strict_variables' => false,
107-
'exception_controller' => 'AcmeFooBundle:Exception:showException',
108-
'optimizations' => true,
109-
'paths' => array(
110-
'%kernel.root_dir%/../vendor/acme/foo-bar/templates' => 'foo_bar',
111-
),
105+
),
106+
'globals' => array(
107+
'foo' => '@bar',
108+
'pi' => 3.14,
109+
),
110+
'auto_reload' => '%kernel.debug%',
111+
'autoescape' => 'name',
112+
'base_template_class' => 'Twig_Template',
113+
'cache' => '%kernel.cache_dir%/twig',
114+
'charset' => '%kernel.charset%',
115+
'debug' => '%kernel.debug%',
116+
'strict_variables' => false,
117+
'exception_controller' => 'AcmeFooBundle:Exception:showException',
118+
'optimizations' => true,
119+
'paths' => array(
120+
'%kernel.root_dir%/../vendor/acme/foo-bar/templates' => 'foo_bar',
121+
),
122+
'date' => array(
123+
'format' => 'd.m.Y, H:i:s',
124+
'interval_format' => '%%d days',
125+
'timezone' => 'Asia/Tokyo',
126+
),
127+
'number_format' => array(
128+
'decimals' => 2,
129+
'decimal_point' => ',',
130+
'thousands_separator' => '.',
131+
),
112132
));
113133
114134
.. caution::
@@ -208,6 +228,37 @@ charset
208228
The charset used by the template files. In the Symfony Standard edition this
209229
defaults to the ``UTF-8`` charset.
210230

231+
date
232+
~~~~
233+
234+
These options define the default values used by the ``date`` filter to format
235+
date and time values. They are useful to avoid passing the same arguments on
236+
every ``date`` filter call.
237+
238+
format
239+
......
240+
241+
**type**: ``string`` **default**: ``F j, Y H:i``
242+
243+
The format used by the ``date`` filter to display values when no specific format
244+
is passed as argument.
245+
246+
internal_format
247+
...............
248+
249+
**type**: ``string`` **default**: ``%d days``
250+
251+
The format used by the ``date`` filter to display ``DateInterval`` instances
252+
when no specific format is passed as argument.
253+
254+
timezone
255+
........
256+
257+
**type**: ``string`` **default**: (the value returned by ``date_default_timezone_get()``)
258+
259+
The timezone used when formatting date values with the ``date`` filter and no
260+
specific timezone is passed as argument.
261+
211262
debug
212263
~~~~~
213264

@@ -232,6 +283,38 @@ option is advanced. If you need to customize an error page you should use
232283
the previous link. If you need to perform some behavior on an exception,
233284
you should add a listener to the ``kernel.exception`` event (see :ref:`dic-tags-kernel-event-listener`).
234285

286+
number_format
287+
~~~~~~~~~~~~~
288+
289+
These options define the default values used by the ``number_format`` filter to
290+
format numeric values. They are useful to avoid passing the same arguments on
291+
every ``number_format`` filter call.
292+
293+
decimals
294+
........
295+
296+
**type**: ``integer`` **default**: ``0``
297+
298+
The number of decimals used to format numeric values when no specific number is
299+
passed as argument to the ``number_format`` filter.
300+
301+
decimal_point
302+
.............
303+
304+
**type**: ``string`` **default**: ``.``
305+
306+
The character used to separate the decimals from the integer part of numeric
307+
values when no specific character is passed as argument to the ``number_format``
308+
filter.
309+
310+
thousands_separator
311+
...................
312+
313+
**type**: ``string`` **default**: ``,``
314+
315+
The character used to separate every group of thousands in numeric values when
316+
no specific character is passed as argument to the ``number_format`` filter.
317+
235318
optimizations
236319
~~~~~~~~~~~~~
237320

0 commit comments

Comments
 (0)