A while ago I asked how to check if a plugin is enabled/installed. I've since used a couple methods to do my checks:

{% set plugin = craft.plugins.getPlugin('myPlugin', false) %}

{{ plugin.isEnabled() ? 'plugin enabled' : 'plugin disabled'}} <br/>
{{ plugin.isInstalled() ? 'plugin installed' : 'plugin not installed'}} <br/>

{{ craft.myPlugin is defined ? 'plugin true' : 'plugin false' }}

Now I recall this working with Twig Extension functions and filters too. It wasn't pretty, but it worked.

I may wrong, but I think one of the Craft CMS Updates have broken this. Because as-of-late, when I do something like this:

{{ craft.myPlugin is defined ? myFunction() }}


{{ craft.myPlugin is defined ? someVariable|myFilter() }}

(myFunction being a twig function, and myFilter being a twig filter)... I get an error:

Unknown "myFunction" function

Another new change/bug I've noticed (related to this); if a database can't be connected to and devMode is off, I will get this instead of the 503 error template.

Unknown "myFunction" function in "_layouts/main" at line 85.

It's as if the Twig functions/filters get priority over anything else. Am I making this up, and this has always been the case? Or has something changed?

  • I'm also experiencing some what Mark Bolton is seeing... that is if a plugin is disabled or not installed: the conditionals fail with the Unknown "myFunction" function. For example, trying to confirm that Cookies is installed & enabled, following throws the Unknown function error if it's not installed: {{ craft.cookies is defined ? getCookie() }} However, the following does not throw the error: {{ craft.cookies is defined ? craft.cookies.get() }} Skimming through the Cookies code, I don't see anything immediately obvious as to the difference
    – user7830
    Commented Jan 9, 2018 at 19:50

1 Answer 1


I just a test of this locally in a sample plugin and I get expected behavior.

If I install and enable the plugin in Craft and use this in a template:

{% set plugin = craft.plugins.getPlugin('myPlugin', false) %}

{{ plugin.isEnabled() ? 'plugin enabled' : 'plugin disabled'}}<br/>
{{ plugin.isInstalled() ? 'plugin installed' : 'plugin not installed'}}<br/>

{{ craft.myPlugin is defined ? 'plugin true' : 'plugin false' }}

I get this output:

plugin enabled 
plugin installed 
plugin true

If I add a Twig Extension class to the plugin, then register a myPluginTestFunction function that outputs "It Works"... i.e.

public function getFunctions()
    return array(
        'myPluginTestFunction' => new Twig_Filter_Method($this, 'myPluginTestFunction', array('is_safe' => array('html'))),

public function myPluginTestFunction()
    return 'It Works';

Then I do this is a template:

{{ craft.myPlugin is defined ? myPluginTestFunction() }}

Then I get the expected output of:

It Works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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