Let's say I've got a hot plugin called Cornballer, and I'd like to avoid embarrassing template errors if I refer to it in a template without yet installing it.

I'd like to get away with this...

 {% if craft.cornballer %}

 {{ craft.cornballer.simulate('little') }}

 {% endif %}

...so that any cornballing is simply ignored and no errors result. But Craft allows no such thing:

Method "cornballer" for object "Craft\CraftVariable" does not exist

Is there a way?


This should do it:

{% if craft.cornballer is defined %}
    Never fear... CornBaller is here.
{% else %}
    I'm missing my CornBaller.
{% endif %}
  • Damn. I'm embarrassed that is defined didn't occur to me. Thank you, Brad.
    – Matt Stein
    Feb 6 '15 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.