jekyll Collections Accessing A Specific Collection Item


As of Jekyll 3.2, you can use the filter where_exp to filter a collection by any of its properties.

Say you have the following collection item in an "albums" collection:

title: My Amazing Album

You can combine the where_exp and first filters to grab just that one item:

{% assign album = site.albums 
    | where_exp:"album", "album.title == 'My Amazing Album'" 
    | first %}

The first filter is necessary because where_exp returns an array of matched items.

You can then use it any way you'd like:

<h1>{{ album.title }}</h1>