Jekyll for loop over all images in a folder?

This worked like a charm for me. No plugins required.

My images are in a assets/images/slider directory.

{% for image in site.static_files %}
    {% if image.path contains 'images/slider' %}
        <img src="https://stackoverflow.com/questions/17677094/{{ site.baseurl }}{{ image.path }}" alt="image" />
    {% endif %}
{% endfor %}

The image.path contains 'images/slider' makes sure that only images in that folder are inserted.

Further reading here and on jekylltalk.

Troubleshooting:
As mentioned in the comments, if you have trouble with this approach, you might want to try removing the indentations before the Tag.

Leave a Comment