Answers.Body: <p>Like Brad says, you'd need to write a custom plugin – specifically, one that provides a <a href="http://buildwithcraft.com/docs/plugins/variables" rel="nofollow">Template Variable</a> class exposing the AssetTransformsService's <a href="https://buildwithcraft.com/classreference/services/AssetTransformsService#getTransformByHandle-detail" rel="nofollow"><code>getTransformByHandle</code></a> method.</p>
  
  <p>The variable class could look something like this:</p>
  
  <pre><code>class MyPluginVariable
  {
  
      public function imageTransformExists($handle)
      {
          // Returns null if transform doesn't exist
          return craft()-&gt;assetTransforms-&gt;getTransformByHandle($handle);
      }
  
  }
  </code></pre>
  
  <p>Then, you'd be able to test for named image transforms in your templates like this:</p>
  
  <pre><code>{% if craft.myPlugin.imageTransformExists('thumb') %}
      ...
  {% endif %}
  </code></pre>
  
  <p>If you're not familiar with plugin development, it might be useful to use the <a href="https://github.com/lindseydiloreto/craft-businesslogic" rel="nofollow">Business Logic plugin</a> as a starting point – it even has a Variable class which you could just drop the above <code>imageTransformExists</code> method into.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-01T08:39:33.790Z
Answers.Text: Thank you very much for the detailed answer 'mmikkel'. Looking into it a little further, it does make sense as to why there isn't a native template-side method for this. As Brad mentions, there are fallbacks already in place. Fortunately for me, this is still going to be of use as I plan to dynamically create this image transform onAfterInstall() on the condition it doesn't already exist.
Answers.UserDisplayName: Mark Notton
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-29T23:22:23.183Z
Answers.LastActivityDate: 2015-09-29T23:22:23.183Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.Body: <p>Nothing native, but it could probably be pulled off with a custom <a href="http://buildwithcraft.com/docs/plugins/introduction" rel="nofollow">plugin</a>.</p>
  
  <p>But just to be clear, if a transform currently doesn't exist then Craft will automatically create it on that request, so the code you shared is pretty much already happening behind the scene.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-29T17:43:51.407Z
Answers.LastActivityDate: 2015-09-29T17:43:51.407Z
Answers.UserDisplayName: Brad Bell
Body: <p>Is there an elegant way to check if an image transform exists?</p>
  
  <pre><code>{% if craft.imageTransformExists('thumb') %}
    &lt;img src="{{asset.getUrl(thumb)}}" alt="Image"&gt;
  {% else %}
    This image transform doesn't exists, please create it
  {% endif %}
  </code></pre>
  
Tags: <image-transforms>
Title: How to check if an Image Transform exists?
ThreadText: # How to check if an Image Transform exists?
  
  (Asked by: username_0 on 2015-09-29)
  
  Is there an elegant way to check if an image transform exists?
  
  ```
  {% if craft.imageTransformExists('thumb') %}
    <img src="{{asset.getUrl(thumb)}}" alt="Image">
  {% else %}
    This image transform doesn't exists, please create it
  {% endif %}
  
  ```
  
  **Tags:** image-transforms
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-09-29. Score: 4 | Accepted answer
  
  Like username_2 says, you'd need to write a custom plugin – specifically, one that provides a [Template Variable](http://buildwithcraft.com/docs/plugins/variables) class exposing the AssetTransformsService's [`getTransformByHandle`](https://buildwithcraft.com/classreference/services/AssetTransformsService#getTransformByHandle-detail) method.
  
  The variable class could look something like this:
  
  ```
  class MyPluginVariable
  {
  
      public function imageTransformExists($handle)
      {
          // Returns null if transform doesn't exist
          return craft()->assetTransforms->getTransformByHandle($handle);
      }
  
  }
  
  ```
  
  Then, you'd be able to test for named image transforms in your templates like this:
  
  ```
  {% if craft.myPlugin.imageTransformExists('thumb') %}
      ...
  {% endif %}
  
  ```
  
  If you're not familiar with plugin development, it might be useful to use the [Business Logic plugin](https://github.com/lindseydiloreto/craft-businesslogic) as a starting point – it even has a Variable class which you could just drop the above `imageTransformExists` method into.
  
  > **Comments:**
  > **username_0**: Thank you very much for the detailed answer 'mmikkel'. Looking into it a little further, it does make sense as to why there isn't a native template-side method for this. As username_2 mentions, there are fallbacks already in place. Fortunately for me, this is still going to be of use as I plan to dynamically create this image transform onAfterInstall() on the condition it doesn't already exist.  
  
  ---
  
  ### Answer by username_2 on 2015-09-29. Score: 3
  
  Nothing native, but it could probably be pulled off with a custom [plugin](http://buildwithcraft.com/docs/plugins/introduction).
  
  But just to be clear, if a transform currently doesn't exist then Craft will automatically create it on that request, so the code you shared is pretty much already happening behind the scene.
  
  
  ---
  
  