André Luiz André Luiz - 3 months ago 16
PHP Question

Phalcon PhP - Unkown filter

I'm trying to create custom filter for currency so I can use in my .volt templates. This is how I register the filter in my services.php

$di->setShared('filter', function() {
$filter = new \Phalcon\Filter();
$filter->add('currency', function ($value) {
if($value === '') {
return NULL;
} else {
return $value; // @todo implement the currency formatting
}
});
return $filter;
});


Then when I try to use it in my .volt template, like this
{{ quote['total_fees']|currency }}
I get the following message
Unknown filter "currency"
.

Can you see what I'm doing wrong?

Thanks for any help

Answer

I think i already posted link, but okay, here you go again - https://docs.phalconphp.com/pl/latest/reference/volt.html#id2. It should look like this:

$di->set('view', function() {
    $view = new View();
    $view->registerEngines([
        '.volt' => function($view, $di) {
            $volt = new Volt($view, $di);
            $compiler = $volt->getCompiler();
            $compiler->addFilter('currency',your code);
        }
    ]);
    return $view;
});
Comments