Thomas' Tech Tips

Sort collection by property in Jekyll liquid template

23 June 2023 - Thomas Damgaard

This will sort a collection by the front matter variable date then iterate through the sorted collection:

{% assign items_sorted = site.items | sort: 'date' %}
{% for item in items_sorted %}
    <a href="{{ item.url }}">{{ item.title }}</a>
{% endfor %}

To sort in reverse order, use | reverse:

{% assign items_sorted = site.items | sort: 'date' | reverse %}
{% for item in items_sorted %}
    <a href="{{ item.url }}">{{ item.title }}</a>
{% endfor %}
Filed under: howto, jekyll, liquid, markdown, template, tips, web

Back to article list