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')

2 Answers 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.


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 %}

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.