Skip to navigation Skip to main content
🇺🇦🇺🇦🇺🇦 Stand with Ukraine 🇺🇦🇺🇦🇺🇦
Eleventy
Eleventy Documentation
Stable
2.0.1
Canary
3.0.0-alpha.6
Toggle Menu
Eleventy 1.93s
Astro 22.90s

Get Next or Previous Collection Item Universal Filters

Contents

getPreviousCollectionItem and getNextCollectionItem Jump to heading

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

View this example in: Liquid Nunjucks 11ty.js Handlebars
Syntax Liquid
{% assign previousPost = collections.posts | getPreviousCollectionItem: page %}
{% assign nextPost = collections.posts | getNextCollectionItem: page %}

<!-- in v2.0.0 the page argument is optional -->
{% assign previousPost = collections.posts | getPreviousCollectionItem %}
{% assign nextPost = collections.posts | getNextCollectionItem %}
Syntax Nunjucks
{% set previousPost = collections.posts | getPreviousCollectionItem(page) %}
{% set nextPost = collections.posts | getNextCollectionItem(page) %}

<!-- in v2.0.0 the page argument is optional -->
{% set previousPost = collections.posts | getPreviousCollectionItem %}
{% set nextPost = collections.posts | getNextCollectionItem %}

This example has not yet been added—you can swap to another template language above! Or maybe you want to contribute it? Edit this page

This example has not yet been added—you can swap to another template language above! Or maybe you want to contribute it? Edit this page

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

View this example in: Liquid Nunjucks 11ty.js Handlebars

The Collections documentation outlines the default sorting algorithm and how to override it.

getCollectionItemIndex Added in v2.0.0 Jump to heading

The getCollectionItemIndex filter returns the 0-based numeric index of the current (or passed) page in the collection.

View this example in: Liquid Nunjucks 11ty.js Handlebars
Syntax Liquid
{% assign index = collections.posts | getCollectionItemIndex %}

Or pass it in:
{% assign index = collections.posts | getCollectionItemIndex: page %}
Syntax Nunjucks
{% set index = collections.posts | getCollectionItemIndex %}

Or pass it in:
{% set index = collections.posts | getCollectionItemIndex(page) %}

This example has not yet been added—you can swap to another template language above! Or maybe you want to contribute it? Edit this page

This example has not yet been added—you can swap to another template language above! Or maybe you want to contribute it? Edit this page

getCollectionItem Jump to heading

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

View this example in: Liquid Nunjucks 11ty.js Handlebars
Syntax Liquid
{% assign currentPost = collections.posts | getCollectionItem: page %}

<!-- in v2.0.0 the page argument is optional -->
{% assign currentPost = collections.posts | getCollectionItem %}
Syntax Nunjucks
{% set currentPost = collections.posts | getCollectionItem(page) %}

<!-- in v2.0.0 the page argument is optional -->
{% set currentPost = collections.posts | getCollectionItem %}

This example has not yet been added—you can swap to another template language above! Or maybe you want to contribute it? Edit this page

This example has not yet been added—you can swap to another template language above! Or maybe you want to contribute it? Edit this page


Other pages in Filters: