【问题标题】:How to install twig localizeddate filter?如何安装树枝本地化日期过滤器?
【发布时间】:2014-07-10 23:28:27
【问题描述】:

我有 PHP 5.5.9 并且我激活了php_intl.dll exyention 并在活动的 php.ini 中将其配置设置为如下:

[intl]
intl.default_locale = ar
; This directive allows you to produce PHP errors when some error
; happens within intl functions. The value is the level of the error produced.
; Default is 0, which does not produce any errors.
;intl.error_level = E_WARNING

当我尝试以下树枝代码时:

{{ item.get_date('j F Y | g:i a')|localizeddate('medium', 'none', locale) }}

我遇到了一个致命错误:

致命错误: 未捕获的异常 'Twig_Error_Syntax' 带有消息“第 53 行的“index.html”中不存在过滤器“localizeddate”' 在

官方文档there 没有显示如何安装或添加这个过滤器到树枝。我使用没有 Symfony 的简单 PHP 应用程序。树枝版 1.16.0

【问题讨论】:

    标签: php twig template-engine


    【解决方案1】:

    您正在寻找 twig/extensions composer 包,github 存储库位于 fabpot/Twig-extensions

    你提到你正在使用独立的树枝,那么你必须有一个 Twig_Environment 对象。它有一个addExtension 方法,你需要调用它,传递一个新的 Intl 扩展实例:

    $env->addExtension(new Twig_Extensions_Extension_Intl());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-30
      • 2012-03-17
      • 2016-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多