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

Add Global Function to Volt Compiler

Hi,

I'm trying to implement that converting all strings to function.

$compiler->addFunction('*', function ($resolvedArgs, $exprArgs){
    return 'call_user_func(' . $resolvedArgs . ')';
});

My helper:

function foo {}
function bar {}
function theme_url {}

For example usage on volt:

{{ foo('hello') }}

{{ bar('world') }}

{{ theme_url('path') }}

I tried with * sign but didnt work

Phalcon\Mvc\View\Exception: Macro 'theme_url' does not exist



145.0k
Accepted
answer

Why even use global functions? Why just not put those functions into class and put this class into di?



58.1k

Great idea! Thank you so much

Why even use global functions? Why just not put those functions into class and put this class into di?