<p>I can't think of a native way to do this, but Twig does have a <a href="https://github.com/twigphp/Twig/blob/1.x/lib/Twig/Environment.php#L736" rel="nofollow noreferrer">hasExtension</a> method, which you could make use of in a Craft plugin.  But if you wrote a plugin to utilize it (similar to <a href="https://stackoverflow.com/a/28772193/684">this</a>) obviously that wouldn't help if the plugin was disabled or uninstalled.</p>

<p>Alternatively, you can add this as a <a href="http://feedback.buildwithcraft.com" rel="nofollow noreferrer">feature request</a> 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.</p>

CC BY-SA 3.0
2015-10-14T04:26:04.003Z
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
CC BY-SA 3.0
2015-10-14T00:16:38.930Z
2015-10-14T00:16:38.930Z
2017-05-23T12:38:53.957Z
Brad Bell
<p>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:</p>

<blockquote>
  <p>The "extensionName" extension is not enabled.</p>
</blockquote>

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

<p>However, short of doing a full <a href="https://craftcms.stackexchange.com/questions/10632/how-can-i-check-if-a-plugin-is-installed-and-enabled">check on wether my plugin is installed</a> 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). </p>

<p>Any ideas on a workaround?</p>

<plugin-development><templating>
Is there a fallback when a Twig extension is not enabled?
# Is there a fallback when a Twig extension is not enabled?

(Asked by: username_0 on 2015-10-13)

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](https://craftcms.stackexchange.com/questions/10632/how-can-i-check-if-a-plugin-is-installed-and-enabled) 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?

**Tags:** plugin-development, templating


---

## 1 answers

### Answer by username_1 on 2015-10-14. Score: 2

I can't think of a native way to do this, but Twig does have a [hasExtension](https://github.com/twigphp/Twig/blob/1.x/lib/Twig/Environment.php#L736) method, which you could make use of in a Craft plugin. But if you wrote a plugin to utilize it (similar to [this](https://stackoverflow.com/a/28772193/684)) obviously that wouldn't help if the plugin was disabled or uninstalled.

Alternatively, you can add this as a [feature request](http://feedback.buildwithcraft.com) 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.

> **Comments:**
> **username_2**: 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.  

---

