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.

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>


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