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.

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



7.3k
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) %}