How to list files in a directory with Liquid?

后端 未结 8 1563
日久生厌
日久生厌 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:28

    The Jekyll:DirectoryTag plugin from SillyLogger

    This tag lets you iterate over files at a particular path. The directory tag yields a file object and a forloop object. If files conform to the standard Jekyll format, YYYY-MM-DD-file-title, then those attributes will be populated on that file object.

    For example with images

    <ul>
      {% directory path: images/vacation exclude: private %}
        <li>
          <img src="{{ file.url }}"
               alt="{{ file.name }}"
               datetime="{{ file.date | date_to_xmlschema }}" />
        </li>
      {% enddirectory %}
    </ul>
    
    0 讨论(0)
  • 2020-12-28 14:30

    You can use this plugin. Copy and paste this code in a file inside the _plugins directory at the root of your Jekyll project.

    https://gist.github.com/jgatjens/8925165

    Then to use it just add the lines below

    {% loop_directory directory:images iterator:image filter:*.jpg sort:descending %}
       <img src="{{ image }}" />
    {% endloop_directory %}
    
    0 讨论(0)
提交回复
热议问题