We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 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>


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() }}