So I have a plugin with a Twig Extension that does it's thing. If I were to disable my plugin I will get the expected error:

The "extensionName" extension is not enabled.

Whenever I'm referring to anything to do with my plugin, I rely on the usual "is defined", "is not empty", "|default()", etc... options as appropriate fallbacks/checks incase my plugin fails.

However, short of doing a full check on wether my plugin is installed everytime, there doesn't seem to be an elegant solution for checking extensions are enabled until it's too late (and the page fails to load).

Any ideas on a workaround?

1 Answer 1


I can't think of a native way to do this, but Twig does have a hasExtension method, which you could make use of in a Craft plugin. But if you wrote a plugin to utilize it (similar to this) obviously that wouldn't help if the plugin was disabled or uninstalled.

Alternatively, you can add this as a feature request to add to Craft natively. If you go that route, be sure and go into details on your specific use-case as I'm not sure I'm following it 100% here.

  • 4
    I would vote for that feature request, here's an example use case... The common "best approach" to managing DB & file syncing across environments is files go up, database comes down. But if you need files to go up to a live site which include a new Twig filter, you've got to do it in multiple steps: (1) Upload plugin with filter, (2) Enable plugin, (3) Upload templates which use the new filter. Allowing Craft to fail gracefully when a filter doesn't exist would make it possible to upload everything at once, greatly simplifying this process.
    – Lindsey D
    Oct 14, 2015 at 4:26

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.