Jekyll for循环查看文件夹中的所有图像? [英] Jekyll for loop over all images in a folder?

查看:61
本文介绍了Jekyll for循环查看文件夹中的所有图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的jekyll博客上做一个简单的投资组合.我所有的图像文件都放在一个文件夹中.

I'd like to make a dirt-simple portfolio of sorts on my jekyll blog. I have all my image files in a folder.

目前,我可以像这样生成照片页面:

Currently, I have it generating the photos page like this:

<p style="line-height: 100px;">
<img src="photos/01.jpg"><br>
<img src="photos/02.jpg"><br>
<img src="photos/03.jpg"><br>
<img src="photos/04.jpg"><br>
<img src="photos/05.jpg"><br>
<img src="photos/06.jpg"><br>
<img src="photos/07.jpg"><br>
<img src="photos/08.jpg"><br>
<img src="photos/09.jpg"><br>
<img src="photos/10.jpg"><br>
</p>

如果我要添加或删除新照片,那根本不方便.是否可以做类似for帖子的for循环:

Which isn't convenient at all if I want to add or remove new photographs. Is it possible to do something like the for loop I have for posts:

{% for post in site.posts %}
     <h2><a href="{{ post.url }}">{{ post.title }}</a></h2>
{% endfor %}

除了循环播放所有图像之外?

Except to loop over all the images?

谢谢!

推荐答案

这对我来说就像是一种魅力.无需插件.

This worked like a charm for me. No plugins required.

我的图像位于assets/images/slider目录中.

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

image.path contains 'images/slider'确保仅插入该文件夹中的图像.

The image.path contains 'images/slider' makes sure that only images in that folder are inserted.

进一步阅读此处故障排除: 如评论中所述,如果您对这种方法有疑问,则可能要尝试删除Tag之前的缩进.

Troubleshooting: As mentioned in the comments, if you have trouble with this approach, you might want to try removing the indentations before the Tag.

这篇关于Jekyll for循环查看文件夹中的所有图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆