Answers.Body: <p>you can check if the plugin is installed and enabled with:</p>
  
  <pre><code>{% if craft.app.plugins.isPluginEnabled('assetrev') %}
    {% set fileName = rev(file) %}
  {% else %}
    {% set fileName = file %}
  {% endif %}
  </code></pre>
  
  <p>you won't need the extra check <code>craft.app.plugins.isPluginInstalled('assetrev')</code> then.</p>
  
  <p><a href="https://docs.craftcms.com/api/v3/craft-services-plugins.html#method-ispluginenabled" rel="nofollow noreferrer">isPluginEnabled()</a>:</p>
  
  <blockquote>
    <p>Returns whether a given plugin is installed and enabled.</p>
  </blockquote>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-27T06:33:44.497Z
Answers.Text: true, but using `rev` in templates still causes error.
Answers.UserDisplayName: Piotr Pogorzelski
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-27T05:46:51.677Z
Answers.LastActivityDate: 2019-06-27T05:46:51.677Z
Answers.UserDisplayName: HendrikEng
Body: <p>I want to use <a href="https://github.com/clubstudioltd/craft-asset-rev" rel="nofollow noreferrer">asset rev</a> in my template, but only if plugin is installed and enabled:</p>
  
  <pre><code>    {% if craft.app.plugins.getPlugin('assetrev') is not null and craft.app.plugins.getPlugin('assetrev').isInstalled %}
          {% set fileName = rev(file) %}
      {% else %}
          {% set fileName = file %}
      {% endif %}
  </code></pre>
  
  <p>Hovewer when i disable plugin, mere existence of <code>rev</code> function in my template, still causes error.</p>
  
Tags: <templating><plugins>
Title: Use function provided by plugin only if plugin is installed and enabled
ThreadText: # Use function provided by plugin only if plugin is installed and enabled
  
  (Asked by: username_0 on 2019-06-26)
  
  I want to use [asset rev](https://github.com/clubstudioltd/craft-asset-rev) in my template, but only if plugin is installed and enabled:
  
  ```
      {% if craft.app.plugins.getPlugin('assetrev') is not null and craft.app.plugins.getPlugin('assetrev').isInstalled %}
          {% set fileName = rev(file) %}
      {% else %}
          {% set fileName = file %}
      {% endif %}
  
  ```
  
  Hovewer when i disable plugin, mere existence of `rev` function in my template, still causes error.
  
  **Tags:** templating, plugins
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-06-27. Score: 1
  
  you can check if the plugin is installed and enabled with:
  
  ```
  {% if craft.app.plugins.isPluginEnabled('assetrev') %}
    {% set fileName = rev(file) %}
  {% else %}
    {% set fileName = file %}
  {% endif %}
  
  ```
  
  you won't need the extra check `craft.app.plugins.isPluginInstalled('assetrev')` then.
  
  [isPluginEnabled()](https://docs.craftcms.com/api/v3/craft-services-plugins.html#method-ispluginenabled):
  
  > Returns whether a given plugin is installed and enabled.
  
  > **Comments:**
  > **username_0**: true, but using `rev` in templates still causes error.  
  
  ---
  
  