In Jekyll how do I for loop through a collection sorted by a field?
- User
In Jekyll how do I for loop through a collection sorted by a field?
Assistant
In Jekyll, you can loop through a collection sorted by a field using the
sortfilter. Here's the syntax:liquid{% for item in site.collection_name | sort: 'field_name' %} <!-- your content here --> {% endfor %}For example, if you have a collection called
postsand want to sort by adatefield:liquid{% for post in site.posts | sort: 'date' %} <h2>{{ post.title }}</h2> <p>{{ post.date }}</p> {% endfor %}You can also sort in reverse order by chaining the filter:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.