【发布时间】:2015-01-26 23:01:29
【问题描述】:
关注http://symfony.com/doc/current/cookbook/templating/twig_extension.html 创建我的自定义 Twig 过滤器,用于我的 Symfony 2 项目。
一切似乎都很好,但是在加载页面时,它说:
The filter "tss" does not exist in AppBundle:Default:status.html.twig at line 7
我的services.yml:
services:
app.twig_extension:
class: AppBundle\Twig\AppExtension
tags:
- { name: twig.extension }
我的src/AppBundle/Twig/AppExtension.php:
<?php
namespace AppBundle\Twig;
class AppExtension extends \Twig_Extension
{
public function getFilter()
{
return [
new \Twig_SimpleFilter('tss', [$this, 'tssFilter']),
];
}
public function tssFilter(\DateTime $timestamp)
{
return 'ready';
}
public function getName()
{
return 'app_extension';
}
}
我错过了什么吗?
感谢您的建议。
【问题讨论】: