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

is defined shortcut

Hey, guys, right now, if I want to check if a variable is defined before printing it I have to do:

{% if foo.bar is defined %}{{ foo.bar }}{% endif %}

Wouldn't it be nice to have a shortcut for this (in case it doesn't exist) ? Something similar to this:

{{ foo.bar ? "alternative text" }}



98.9k
Accepted
answer

Hey, maybe this could work:

{{ a is defined ? "hello" : null }}

Hello from 2016 :)

Very useful, didnt know that!