Reputation: 3365
I've got a nested for loop which is checking to see if a file path name matches a piece of front-matter in one of my posts. The trouble I'm having is that for whatever reason the if statement isn't working, even though I can print both file.path
and post.assets
right before the if statement, any idea why this isn't working?
{% for post in site.posts limit:3 %}
urlsToCache.push("{{ post.url }}")
{% for file in site.static_files %}
{% if file.path contains '{{ post.assets }}' %}
urlsToCache.push("{{ file.path }}")
{% endif %}
{% endfor %}
{% endfor %}
If printed right before I have the following which leads me to believe {% if file.path contains '{{ post.assets }}' %}
should work, but it's not.
jekyll-sw
/assets/posts/jekyll-sw/montezuma_sw.jpg
Help would be appreciated!
Upvotes: 1
Views: 77
Reputation: 23982
When accessing a variable inside an if statement avoid surrounding them with curly braces, it can be accessed directly like:
{% if file.path contains post.assets %}
urlsToCache.push("{{ file.path }}")
{% endif %}
Upvotes: 1