Hot answers tagged


is defined - The variable has been defined, and set to any value (or null). is not null - The variable has been defined, and is specifically not null. In PHP terms, it's like the difference between is_null() vs. checking whether the variable exists using get_defined_vars() (see this Stack Overflow thread for a little more clarity) Try this experiment... ...


The first statement checks for the existence of var, the second checks that it has a value other than null and will throw and error if var does not exist. If you're not sure whether a variable exists, you should check if it exists first then check for its value to be safe. You could combine both statements like so {% if var is defined and var is not null %}...


You could combine the first three: {% if entry is defined and entry and entry.isEditable %} If the first or second part of this logic fails, it will not check the third part so no error will be thrown. The second part is for the rare cases that a variable with the name entry exists but is null. If entry is defined, it's always an entry (or at least it ...


This is a weird twig behavior. You have to do if stRow['caption'] is defined to make it work because of the object syntax of twig. Sometimes the if defined statement becomes true when you don't use the array syntax

Only top voted, non community-wiki answers of a minimum length are eligible