Eleventy The possum is Eleventy’s mascot

Eleventy Documentation

This is an older version of Eleventy. Go to the newest Eleventy docs (current path: /docs/filters/collection-items/) or the full release history.
Menu

Get Next or Previous Collection Item Universal Filters #

New in v0.11.0 Fetch the previous and next items in a collection when you pass in the current page object.

Syntax Nunjucks
{% set previousPost = collections.posts | getPreviousCollectionItem(page) %}
{% set nextPost = collections.posts | getNextCollectionItem(page) %}
Syntax Liquid
{% assign previousPost = collections.posts | getPreviousCollectionItem: page %}
{% assign nextPost = collections.posts | getNextCollectionItem: page %}

Useful when you’d like to link to the previous or next template in your collection:

Syntax Nunjucks, Liquid
{% if previousPost %}Previous Blog Post: <a href="{{ previousPost.url }}">{{ previousPost.data.title }}</a>{% endif %}
Syntax Nunjucks, Liquid
{% if nextPost %}Next Blog Post: <a href="{{ nextPost.url }}">{{ nextPost.data.title }}</a>{% endif %}

Also getCollectionItem #

For completeness, a getCollectionItem filter is also included that fetches the current page from a collection.

Syntax Nunjucks
{{ set currentPost = collections.posts | getCollectionItem(page) }}

Other pages in Filters: