How to list files in a directory with Liquid?

后端 未结 8 1598
日久生厌
日久生厌 2020-12-28 14:01

I\'m trying to learn how to use Jekyll along with Bootstrap; while studying them, I decided that I\'d like to have an image carousel on my homepage.

Since I\'m real

8条回答
  •  时光取名叫无心
    2020-12-28 14:26

    Using the Jekyll collections API, which, as of 2015-08-07 came with the big warning

    Collections support is unstable and may change

    Define a collection in _config.yml and creates an _images folder in your root directory

    collections:
    - images
    

    Without having to add YAML front-matter to your images, Jekyll will:

    Files in collections that do not have front matter are treated as static files and simply copied to their output location without processing.

    Static files have the following attributes:

    • file.path
    • file.extname

    And then the code on your page would be something like (untested):

    {% for image in site.images %}
         {% if image.extname == 'jpg' %}
             
         {% endif %}
    {% endfor %}
    

提交回复
热议问题