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

call constants in the volt

Hello all!

How to call some constants of model???

Until now calling constant and static method is not yet supported in volt, but you can use php tag in volt. Below is the example of volt script using ERROR logger constant.

<? $logErrorVal = Phalcon\Logger::ERROR ?>

<p> The error constant of Phalcon Logger error is {{ logErrorVal}} </p>


98.9k
Accepted
answer

Use the function constant():

{{ constant("DIRECTORY_SEPARATOR") }}
{{ constant("Phalcon\Logger::ERROR") }}

Ouch right, constant() is available since ver 0.8. I didn't follow. But calling static method in volt is still not supported and the workaround is using php tag.

edited Nov '16

Static method in Volt - there's no support for it in Phalcon 3.0.x still.

This is the most confortable solution to the problem:

$voltCompiler->addFunction('myVoltFunction', function () {
                return __NAMESPACE__ . '\\' . 'AnotherClass::getMyRealStaticMethod()';
                }
            );

Volt usage as regular: {{ myVoltFunction() }}