0

I have used this answer https://stackoverflow.com/a/34783367/1279102; but am unable to work out how to use a variable folder.

{% for image in site.static_files %}
    {% if image.path contains '{{ page.gallery }}' %}
        <img src="{{ site.baseurl }}{{ image.path }}" alt="image" />
    {% endif %}
{% endfor %}

I have added 'gallery' to the front matter of my post. I have tried using the absolute path, and the relative path.

It appears that no matter how you add the {{ page.gallery }} variable in the if portion, it is not changed to the corrected value.

What am I missing?

Community
  • 1
  • 1
tithij
  • 29
  • 8

1 Answers1

2

you can't interpolate within liquid tags. assign the value to the variable beforehand.

{% capture ipath %}{{ page.gallery }}{% endcapture %}

{% for image in site.static_files %}
    {% if image.path contains ipath %}
        <img src="{{ site.baseurl }}{{ image.path }}" alt="image" />
    {% endif %}
{% endfor %}
ashmaroli
  • 5,209
  • 2
  • 14
  • 25
  • This is working. But is there any way to exclude @2x files and show them in `srcset=""` property for constructing responsive images? – fatihturan Aug 16 '19 at 18:58