Skip to content

Added docs for "date" and "number_format" Twig options #8116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 103 additions & 17 deletions reference/configuration/twig.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ TwigBundle Configuration ("twig")
paths:
'%kernel.root_dir%/../vendor/acme/foo-bar/templates': foo_bar

# The following were added in Symfony 2.7.
date:
format: d.m.Y, H:i:s
interval_format: '%%d days'
timezone: Asia/Tokyo
number_format:
decimals: 2
decimal_point: ','
thousands_separator: '.'

.. code-block:: xml

<!-- app/config/config.xml -->
Expand All @@ -79,6 +89,9 @@ TwigBundle Configuration ("twig")

<twig:global key="foo" id="bar" type="service" />
<twig:global key="pi">3.14</twig:global>

<twig:date format="d.m.Y, H:i:s" interval-format="%d days" timezone="Asia/Tokyo" />
<twig:number-format decimals="2" decimal-point="," thousands-separator="." />

<twig:exception-controller>AcmeFooBundle:Exception:showException</twig:exception-controller>
<twig:path namespace="foo_bar">%kernel.root_dir%/../vendor/acme/foo-bar/templates</twig:path>
Expand All @@ -92,23 +105,33 @@ TwigBundle Configuration ("twig")
'form_themes' => array(
'form_div_layout.html.twig', // Default
'form.html.twig',
),
'globals' => array(
'foo' => '@bar',
'pi' => 3.14,
),
'auto_reload' => '%kernel.debug%',
'autoescape' => 'name',
'base_template_class' => 'Twig_Template',
'cache' => '%kernel.cache_dir%/twig',
'charset' => '%kernel.charset%',
'debug' => '%kernel.debug%',
'strict_variables' => false,
'exception_controller' => 'AcmeFooBundle:Exception:showException',
'optimizations' => true,
'paths' => array(
'%kernel.root_dir%/../vendor/acme/foo-bar/templates' => 'foo_bar',
),
),
'globals' => array(
'foo' => '@bar',
'pi' => 3.14,
),
'auto_reload' => '%kernel.debug%',
'autoescape' => 'name',
'base_template_class' => 'Twig_Template',
'cache' => '%kernel.cache_dir%/twig',
'charset' => '%kernel.charset%',
'debug' => '%kernel.debug%',
'strict_variables' => false,
'exception_controller' => 'AcmeFooBundle:Exception:showException',
'optimizations' => true,
'paths' => array(
'%kernel.root_dir%/../vendor/acme/foo-bar/templates' => 'foo_bar',
),
'date' => array(
'format' => 'd.m.Y, H:i:s',
'interval_format' => '%%d days',
'timezone' => 'Asia/Tokyo',
),
'number_format' => array(
'decimals' => 2,
'decimal_point' => ',',
'thousands_separator' => '.',
),
));

.. caution::
Expand Down Expand Up @@ -208,6 +231,37 @@ charset
The charset used by the template files. In the Symfony Standard edition this
defaults to the ``UTF-8`` charset.

date
~~~~

These options define the default values used by the ``date`` filter to format
date and time values. They are useful to avoid passing the same arguments on
every ``date`` filter call.

format
......

**type**: ``string`` **default**: ``F j, Y H:i``

The format used by the ``date`` filter to display values when no specific format
is passed as argument.

internal_format
...............

**type**: ``string`` **default**: ``%d days``

The format used by the ``date`` filter to display ``DateInterval`` instances
when no specific format is passed as argument.

timezone
........

**type**: ``string`` **default**: (the value returned by ``date_default_timezone_get()``)

The timezone used when formatting date values with the ``date`` filter and no
specific timezone is passed as argument.

debug
~~~~~

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

number_format
~~~~~~~~~~~~~

These options define the default values used by the ``number_format`` filter to
format numeric values. They are useful to avoid passing the same arguments on
every ``number_format`` filter call.

decimals
........

**type**: ``integer`` **default**: ``0``

The number of decimals used to format numeric values when no specific number is
passed as argument to the ``number_format`` filter.

decimal_point
.............

**type**: ``string`` **default**: ``.``

The character used to separate the decimals from the integer part of numeric
values when no specific character is passed as argument to the ``number_format``
filter.

thousands_separator
...................

**type**: ``string`` **default**: ``,``

The character used to separate every group of thousands in numeric values when
no specific character is passed as argument to the ``number_format`` filter.

optimizations
~~~~~~~~~~~~~

Expand Down