Skip to content

[DX] [TwigBundle] Allow to configure date and number formats #13552

@javiereguiluz

Description

@javiereguiluz

The problem

When using Twig as a standalone project, you can define the date and number format as follows:

$twig = new Twig_Environment($loader);
$twig->getExtension('core')->setDateFormat('d/m/Y', '%d days');

When using Twig inside a Symfony application, you have to use code like this to define this setting:

$this->get('twig')->getExtension('core')->setDateFormat('d/m/Y', '%d days');

Even worse, some people recommend to create a request listener to set this setting.

In my opinion, having to create a listener, adding ugly code to my controllers and hurting application performance just to set the number or date format for my Twig templates is wrong.

The solution

TwigBundle should expose two new configuration options called number_format and date_format to simply configure these settings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementGood first issueIdeal for your first contribution! (some Symfony experience may be required)TwigBundle

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions