【问题标题】:Symfony - Twig - Filter "localizeddate" doesn't work on DateTimeSymfony - Twig - 过滤器“localizeddate”在 DateTime 上不起作用
【发布时间】:2014-08-14 18:32:53
【问题描述】:

我正在使用树枝,当我应用过滤器时

{{tutoriel.dateCreation | localizeddate('medium', 'none') }} 在我的日期时间,我有这个错误:

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

我哪里错了?

谢谢:)

【问题讨论】:

    标签: symfony twig


    【解决方案1】:

    我找到了解决办法。

    您应该安装了 twig intl 扩展。如果没有,请composer require twig/extensions

    您可以像这样激活 config.yml 或 services.yml 文件中的服务:

    services:
        twig.extension.intl:
            class: Twig_Extensions_Extension_Intl
            tags:
                - { name: twig.extension }
    

    【讨论】:

    • php 环境中还必须有活动的php_intl 扩展。
    • 在 Symfony 4 中,执行 composer require twig/extensions,然后转到 config/packages/twig_extensions.yml,然后取消注释 Intl 行
    • 自 2020 年起,弃用此包。建议像 Breaith 的回答所说的那样使用 twig/intl-extra。
    【解决方案2】:

    我使用了新的树枝过滤器format_date()https://twig.symfony.com/doc/2.x/filters/format_date.html

    1. 安装:composer req twig/intl-extra
    2. 树枝中的用法:
    created_at|format_date('full')
    created_at|format_date('full', '', null, 'gregorian', 'fr')
    created_at|format_date('none', 'MMMM Y', null, 'gregorian', 'fr')
    

    【讨论】:

    猜你喜欢
    • 2015-08-02
    • 1970-01-01
    • 1970-01-01
    • 2012-06-03
    • 2018-09-12
    • 1970-01-01
    • 1970-01-01
    • 2014-04-12
    • 1970-01-01
    相关资源
    最近更新 更多