我已按照主题Symfony2 docs,但我的树枝延伸不被树枝识别/识别。Symfony2 - 自定义树枝延伸不被识别
我的扩展类:
namespace Acme\MyBundle\Twig;
class RoundExtension extends \Twig_Extension
{
public function getFilters()
{
return array(new \Twig_SimpleFilter('round', array($this, 'roundFilter')));
}
public function roundFilter($number, $factor = 4)
{
$round = (ceil($number * $factor))/$factor;
return number_format($round, 2);
}
public function getName()
{
return 'round_extension';
}
}
而且我services.yml:
services:
acme.twig.round_extension:
class: Acme\MyBundle\Twig\RoundExtension
tags:
- { name: twig.extension }
最后,错误:
The filter "round" does not exist in MyBundle:Survey:results.html.twig at line 38
我不知道如何着手。