我从文档中创建了一个简单的 Twig 过滤器:
public function getFilters() {
return array(
'price' => new \Twig_Filter_Method($this, 'priceFilter'),
);
}
public function priceFilter($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',')
{
$price = number_format($number, $decimals, $decPoint, $thousandsSep);
$price = '$' . $price;
return $price;
}
它已在配置中注册(因为在该文件中我有一个运行良好的功能):
services:
sybio.twig_extension:
class: %sybio.twig_extension.class%
tags:
- { name: twig.extension }
但它不起作用,说The filter "price" does not exist
。怎么来的?