Skip to content

Instantly share code, notes, and snippets.

@benstraw
Last active June 15, 2023 22:31
Show Gist options
  • Save benstraw/408fc197336d271448795a785e73b658 to your computer and use it in GitHub Desktop.
Save benstraw/408fc197336d271448795a785e73b658 to your computer and use it in GitHub Desktop.
This Liquid loop for Jekyll sorts a collection by date, to reverse the order add ` | reverse`
{% comment %}
* This loop loops through a collection called `dogs`
* and sorts it by the front matter variable `dob` and than filters
* the collection with `reverse` in reverse order
*
* To make it work I first assigned the data to a new string
* called `sorted_dogos`.
{% endcomment %}
{% assign sorted_dogos = site.dogs | sort: "dob" %}
{% for dog in sorted_dogos %}
Born: {{ dog.dob | date_to_string: "ordinal", "US" }}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment