Loop jekyll data directory files

Published on

Jekyll will look into the _data directory.

Working with yml files is as easy as adding a file in this directory, and Jekyll will expose its contents on the site.data.[YML_FILE_NAME].

In this example, rendering a list of authors listed in a YML file is as easy as:

\{\%\- for authors in site.data.authors limit:8 \-\%\}
  \{\{ authors.name \}\}
\{\%\- endfor \-\%\}

The related Data file is located in _data/authors.yml with the following contents:

  name: Christian
  username: christian
  name: admin
  username: admin

Here, have a slice of pizza 🍕