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.

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" }}



83.4k
Accepted
answer

Hey, maybe this could work:

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

Hello from 2016 :)

Very useful, didnt know that!