<p>See <code>kind</code> in the docs: <a href="https://craftcms.com/docs/templating/assetfilemodel" rel="nofollow noreferrer">https://craftcms.com/docs/templating/assetfilemodel</a></p>

<p>I haven't tried it but I suspect it's something like this:</p>

<pre><code>{% set file = assetsField.first %}
{% if file.kind == 'image' %}
  // blah blah
{% endif %}
</code></pre>

<p>There's also <code>extension</code> but kind is probably better here.</p>

CC BY-SA 3.0
2017-02-18T12:26:38.497Z
2017-02-18T12:26:38.497Z
Clive Portman
<p>In addition to the model’s <code>kind</code> property mentioned in the other answer, there is also a <code>kind</code> parameter for asset criteria models.</p>

<pre><code>{% set containsVid = assetsField.kind('video').total() &gt; 0 %}
</code></pre>

CC BY-SA 3.0
2017-02-18T13:03:25.370Z
2017-02-18T13:03:25.370Z
carlcs
<p>What’s the best way to check if an assets field contains a file of a certain type?</p>

<p>Something to the effect of: <code>if assetsField.contains.file-of-type('image')</code></p>

<templating><assets>
Check if Assets Field Contains File of Type
# Check if Assets Field Contains File of Type

(Asked by: username_0 on 2017-02-18)

What’s the best way to check if an assets field contains a file of a certain type?

Something to the effect of: `if assetsField.contains.file-of-type('image')`

**Tags:** templating, assets


---

## 2 answers

### Answer by username_1 on 2017-02-18. Score: 2

See kind in the docs: https://craftcms.com/docs/templating/assetfilemodel
I haven't tried it but I suspect it's something like this:
{% set file = assetsField.first %}
{% if file.kind == 'image' %}
  // blah blah
{% endif %}

There's also extension but kind is probably better here.


---

### Answer by username_2 on 2017-02-18. Score: 1

In addition to the model’s kind property mentioned in the other answer, there is also a kind parameter for asset criteria models.
{% set containsVid = assetsField.kind('video').total() > 0 %}


---

