I'm trying to get the actual file name of each images when looping through the image assets folder, which looks like:

{% for image in craft.assets.kind('image').folderId('1').order('filename') %}
    <li><a href="#"><img src="{{ image.getUrl() }}" alt="{{ image.title }}"></a></li>
{% endfor %}

I need to be able to include the filename of the image as a data attribute in the <a> tag. I tried all sorts of variations of {{ image.fileName }} but have had no luck. Can't find a solution searching here. Does anyone know how? Better yet - is there a documentation somewhere showing all the available twig attributes for assets/images?

1 Answer 1


image.filename should work unless I'm missing something. Note that it is case-sensitive.

The documentation on AssetFileModel can be found here: http://buildwithcraft.com/docs/templating/assetfilemodel

  • Of course the one variation I did not try was all lowercase. Sigh. That worked. Thanks for answering! Commented Apr 23, 2015 at 18:57
  • It's always that way for me. Sometimes it just takes another set of eyes. Happy to help!
    – Peter Tell
    Commented Apr 23, 2015 at 18:58

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.