Skip to content

Instantly share code, notes, and snippets.

@babsgosgens
Last active May 18, 2022 06:58
Show Gist options
  • Save babsgosgens/cfe94dcbd2e7fdca241b47cdc4ce3edc to your computer and use it in GitHub Desktop.
Save babsgosgens/cfe94dcbd2e7fdca241b47cdc4ce3edc to your computer and use it in GitHub Desktop.
Use 'where_exp' to filter images from static assets – way shorter than building an array with a loop! See answer by Yuri P here: https://stackoverflow.com/questions/45926668/how-do-i-create-an-array-from-a-forloop
{% assign slider_images = "" | split: ',' %}
{% for image in site.static_files %}
{% if image.path contains page.image_namespace %}
{% assign slider_images = slider_images | push: image %}
{% endif %}
{% endfor %}
{% assign slider_images = site.static_files | where_exp: "item", "item.path contains page.image_namespace" %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment