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

Bug in Volt variable tests?

To perform a conditional test in Volt the documentation describes using the is keyword which is equal to using ==, however the documentation also suggests that is not is equal to != however I've just experienced some unexpected behaviour:

{% if element.getLabel() is not empty %}

Throws the following notice:

Notice: Undefined variable: empty

But using

{% if !element.getLabel() is empty %}

Produces the correct behaviour. Is this a bug or is Volt just not intended to be used this way?

You should be able to find the compiled template .php code and see what the actualy difference is between the two syntaxes :)

"volt is not empty" yields some results on google:

https://github.com/phalcon/cphalcon/issues/2221



8.1k
Accepted
answer

You can try another structure with same logic, it works for me

{% if not(element.getLabel() is empty) %}

Thanks - +1'd that issue...

"volt is not empty" yields some results on google:

https://github.com/phalcon/cphalcon/issues/2221

Hadn't thought of using that syntax, thanks.

You can try another structure with same logic, it works for me

{% if not(element.getLabel() is empty) %}