See the accepted answer for the most correct solution to this question. This answer gives an example of how to add a php function to volt though.
While working with the answer to this question , I used the following code to add this function to Volt .
$volt->getCompiler()->addFunction( 'count', function($key) { return "count({$key})"; } );
Put this code where you configured your Volt engine (for example, in my services.php file).
source share