I created a simple Twig filter from documents:
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;
}
It is registered in the configuration (since in this file I have a function that works well):
services:
sybio.twig_extension:
class: %sybio.twig_extension.class%
tags:
- { name: twig.extension }
But that does not work, saying The filter "price" does not exist. Why?
source
share