I want to iterate over each file in _data/sections/
, but have output sorted by data contained in said files (order property). The current output happens to be in the correct order, though I am not sure why, and the order does not change when modifying the sorted property.
The files are structured as follows:
// project/_data/sections/food.yml
title: Food
order: 2
content: "Food ipsum dolor sit amet."
-----
// project/_data/sections/drink.yml
title: Drink
order: 1
content: "Drink ipsum dolor sit amet."
Following the structure found on the Jekyll docs for data files, the for-loop code is as follows:
// project/index.html
// ...
{% for section_hash in site.data.sections | sort: 'order' %}
{% assign section = section_hash[1] %}
<p><strong>{{ section.title }}</strong> - {{ section.content }}</p>
{% endfor %}
// ...
I have also tried to sort the sections before passing them to the for-loop as seen here:
{% assign sections_sorted = sita.data.sections | sort: 'order' %}
{% for section in sections_sorted %}
<p><strong>{{ section.title }}</strong> - {{ section.content }}</p>
{% endfor %}
Finally, I have tried to move the order
property to the front-matter of each section file in _data/sections/
, but that has resulted in the exception: Liquid Exception: no implicit conversion of String into Integer
// project/_data/sections/drink.yml
---
order: 1
---
title: Drink
content: "Drink ipsum dolor sit amet."
Is this possible with files in subdirectories of _data/
? How can I sort the output of these files numerically by order
, reverse-alphabetically by title
, and so on?