In a template, can I check whether a Global field exists, before I try to output its value? I want to ensure the page doesn't break entirely in the unlikely event of the field being removed from the CMS.
If I do:
{% if myGlobalSet.myField is defined %}
Defined.
{% endif %}
then it works as expected; "Defined" isn't displayed if myField
doesn't exist.
But if I have:
{% if myGlobalSet.myField is defined %}
Defined. {{ myGlobalSet.myField }}
{% endif %}
I get:
Craft\GlobalSetModel and its behaviours do not have a method or closure named "myField".
if that field doesn't exist. It's like it's trying to process the field even though it's not defined.