Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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



130.8k
Accepted
answer

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



21.2k

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?