uco/twig-extensions-bundle

此包已被废弃且不再维护。未建议替代包。

Twig 扩展

dev-master / 1.0.x-dev 2012-07-28 19:13 UTC

This package is not auto-updated.

Last update: 2024-08-25 02:41:49 UTC


README

此包提供以下过滤器

  • dateage: 日期过滤器能够格式化日期的年龄:

    文章是在 {{ post.published_at | dateage }} 之前发布的。

    {# 返回 '文章是在 5 天和 1 小时之前发布的。' #}

安装

您需要在 deps 文件上安装子模块:

// deps
[UcoTwigExtensionsBundle]
    git=git://github.com/sgomez/UcoTwigExtensionsBundle.git
    target=/bundles/Uco/TwigExtensionsBundle

然后:

bash$ php bin/vendors install

配置

将以下内容添加到 app/autoload.php 中:

// app/autoload.php
$loader->registerNamespaces(array(
  // ...
  'Uco'              => __DIR__.'/../vendor/bundles',
  // ...
));

并将以下内容添加到 app/AppKernel.php 中:

// app/AppKernel.php
$bundles = array(
  // ...
  new Uco\TwigExtensionsBundle\UcoTwigExtensionsBundle(),
  // ...
);

此过滤器使用翻译服务,因此您需要激活它:

// app/config/config.yml
framework:
    translator:      { fallback: en }

用法

如何使用:

  • 过滤器 dateage

    {{ [datetime 实例或字符串] | dateage }}

您也可以指定时区、消息目录和翻译区域:

{{ [datetime instance or string] | dateage( *timezone*, *catalog*, *locale*) }}
{{ [datetime instance or string] | dateage("Europe/Madrid", "admin")  }}

默认情况下,消息目录是 "TwigExtensionsDate"。