How do I access front matter default values in static files? I’m trying to list all images in my site (in my /images folder) but am having trouble.
With the 3.4.2 release, you can now add defaults for static files. I upgraded to 3.4.2.
In my config file, I added this default:
-
scope:
path: "images/"
values:
image: true
I have an images folder containing a bunch of image files. With this default, each image should have image: true in its front matter.
I want to create a list of all of these images (to fulfill reqs in a manifest for something). Here’s what I tried:
{% for file in site.static_files %}
{% if file.image == true %}
{{file.path}}
{% endif %}
{% endfor %}
It didn’t work.
I’m just not sure how to access the page front matter. Would it be file.image, page.image? I tried various things but none worked.
This is what I ended up doing that did work:
{% for file in site.static_files %}
{% if file.extname == ".png" or file.extname == ".jpg" or file.extname == ".gif" %}
{{file.path}}
{% endif %}
{% endfor %}
```
The problem is that, besides not leveraging the front matter values, the output ends up having lots of white space. It seems with each iteration through the loop, if the condition isn't met, a line break is still created. I was hoping that the front matter approach would eliminate all of that white space.
Thanks for replying. I tried removing / from the images path in the config (then restarted jekyll), but it didn’t seem to do anything. You used file.<front matter property> to access the default front matter property set on those static files?
I copied and pasted your example and it worked just as you have it. file.image works since it is in a for loop and you called it for file. Pretty sure you know that bit though.