We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Ceil, Floor, ROund + Volt

Is it possible to use this php function directly in volt engine ?



8.7k
Accepted
answer

$compiler = $volt->getCompiler(); $compiler->addFilter('round','round');



7.5k

Hi, you can write own custom view helper https://docs.phalcon.io/en/latest/reference/tags.html#creating-your-own-helpers

example:

class Number extends \Phalcon\Tag 
{
    public function round($number, $precision = 0 $mode = PHP_ROUND_HALF_UP)
    {
        return round($number, $precision, $mode); 
    }

    another methods
}

and then in volt

{{ Number.round(100.256, 2) }}