Symfony - Twig - Filter “localizeddate” doesn't work on DateTime

后端 未结 2 1010
鱼传尺愫
鱼传尺愫 2021-01-04 11:31

I\'m using twig and when I apply the filter

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

<
相关标签:
2条回答
  • 2021-01-04 12:17

    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 }
    
    0 讨论(0)
  • 2021-01-04 12:28

    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')
    
    0 讨论(0)
提交回复
热议问题