13

I'm using twig and when I apply the filter

{{tutoriel.dateCreation | localizeddate('medium', 'none') }} on my datetime, I have this error :

The filter "localizeddate" does not exist in Video2LearnAdministrationBundle:VisualisationFicheTutoriel:fiche_tutoriel.html.twig at line 167

Where I'm wrong ?

Thanks :)

Zagloo
  • 1,297
  • 4
  • 17
  • 34

2 Answers2

29

I found the solution.

You should have the twig intl extension installed. if not, do composer require twig/extensions

You may activate the services in config.yml or services.yml file like that:

services:
    twig.extension.intl:
        class: Twig_Extensions_Extension_Intl
        tags:
            - { name: twig.extension }
Rolf
  • 5,550
  • 5
  • 41
  • 61
Zagloo
  • 1,297
  • 4
  • 17
  • 34
  • 1
    Also there must to be active `php_intl` extension in php environment. – Hokusai Mar 22 '17 at 11:55
  • 6
    In Symfony 4, do `composer require twig/extensions`, then go to `config/packages/twig_extensions.yml`, then uncomment the Intl line – Alcalyn Aug 07 '19 at 09:42
  • 2
    Since 2020, this package is abandonned. It's recommended to use twig/intl-extra like Breaith's answer said. – HRoux Feb 04 '21 at 11:11
8

i use a new twig filter format_date() : https://twig.symfony.com/doc/2.x/filters/format_date.html

  1. Install: composer req twig/intl-extra
  2. Usages in twig:
created_at|format_date('full')
created_at|format_date('full', '', null, 'gregorian', 'fr')
created_at|format_date('none', 'MMMM Y', null, 'gregorian', 'fr')
Breith
  • 2,160
  • 1
  • 23
  • 32
  • In Symfony project, you must add it in config/services as explained in this answer post [how-to-install-the-intl-extension-for-twig](https://stackoverflow.com/questions/25948853/how-to-install-the-intl-extension-for-twig) – lionelto Dec 23 '20 at 18:13