I tried Phalcon Volt addExtension to extend the variables available to a Volt template run through the Volt compiler. I tested several combinations of code without success. I then tested addFunction. addFunction appears to create a PHP format string in the template. What should I try next?
The following code adds <?= \x\y::listNames() ?> to the compiled template. $this->volt->addFunction('listNames', '\x\y::listNames');
What I actially want to do is execute the function and return an array in the compiled template.
I switched to the following code. It puts the list of values in the compiled template as a list created at compile time, not execution time. $this->volt->addFunction('listNames', function () { return $this->listNames(); });
Finally I used the following line. $this->volt->addFunction('listNames', function () { return '$names = \x\y::listNames();'; }); This produced the following line in the compiled code. < ?= $names = \x\y::listNames(); ?>