How to replace the "localizeddate" filter from twig/extensions
Asked Answered
S

1

6

I'm currently updating my projects to Symfony 5.1 (where I was previously using Symfony 4.1).

When updating I noticed that I can't install the package twig/extensions anymore, which means I can't use the |localizeddate filter.

This has basically already been discussed here: Composer can't install Twig Extensions

- twig/extensions v1.5.0 requires twig/twig ~1.27|~2.0

According to my composer.lock file, 3.0.3 is installed

        ...
        {
            "name": "twig/twig",
            "version": "v3.0.3",
            ...

But just saying something isn't available anymore does not fix the problem


My only use case right now is the following code:

{{ comment.publishedAt|localizeddate('medium', 'short', null, 'UTC') }}

And here is the docs page, for those unfamiliar: https://twig-extensions.readthedocs.io/en/latest/intl.html#localizeddate

Is there another filter or simply another way of how to replace this?

Silvern answered 4/6, 2020 at 12:7 Comment(1)
you also could have copied the code for localizeddate: github.com/twigphp/Twig-extensions/blob/master/src/…Antigone
S
7

The twig/extensions got split up into multiple smaller projects.

So for this case, I had to do

composer require twig/intl-extra

(See: https://github.com/twigphp/intl-extra)

And replace the code with:

{{ comment.publishedAt|format_datetime('medium', 'short', null, 'UTC') }}

(Whether the code works, still has to be tested)

Silvern answered 4/6, 2020 at 12:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.