I'm trying to print my static images in my page following this basic steps in Jekyll documentation:
https://jekyllrb.com/docs/static-files/
My files are in assets/img
and my config file has these lines (space indented)
defaults:
- scope:
path: "assets/img"
values:
image: true
I have a Jekyll brand new website. Now in my about.md
page I want to print all the images:
{% assign image_files = site.static_files | where: "image", true %}
{% for myimage in image_files %}
{{ myimage.path }}
{% endfor %}
Needless to say it prints nothing.
While I can print {{ site.static_files | inspect }}
including all files: fonts, images, zips etc I cannot print image_files
variable, nor myimage
What is happening?
In root project create folders assets
and img
inside assets
folder.
Put your image inside img
Example:
myblog
.
├── 404.html
├── about.md
├── assets
│ └── img
│ └── filename.png
In _config.yml:
defaults:
- scope:
path: "assets/img"
values:
image: true
In your posts, ex:about.md
, put something like that:
{% assign image_files = site.static_files | where: "image", true %}
{% for myimage in image_files %}
![{{myimage.name}}]({{ myimage.path }})
{% endfor %}