Skip to content

Commit

Permalink
Some cleanup for 11ty/eleventy#819 docs
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Feb 12, 2020
1 parent 0930d51 commit 987613e
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions docs/filters/collection-items.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
eleventyNavigation:
parent: Filters
key: Next or Previous Collection Item Filters
title: '<code>get*CollectionItem</code> Filters'
order: 4
excerpt: 'Get next or previous collection items for easy linking.'
---
# `getNextCollectionItem` and `getPreviousCollectionItem` Universal Filters
# Get Next or Previous Collection Item Universal Filters

{% addedin "0.11.0" %} Fetch the previous and next items in a collection when you pass in the current `page` object.

Expand All @@ -21,24 +22,40 @@ eleventyNavigation:
{% codetitle "Liquid", "Syntax" %}

{% raw %}
```
```liquid
{% assign previousPost = collections.posts | getPreviousCollectionItem: page %}
{% assign nextPost = collections.posts | getNextCollectionItem: page %}
```
{% endraw %}

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

{% codetitle "Nunjucks, Liquid", "Syntax" %}

{% raw %}
```
```html
{% if previousPost %}Previous Blog Post: <a href="{{ previousPost.url }}">{{ previousPost.data.title }}</a>{% endif %}
```
{% endraw %}

{% codetitle "Nunjucks, Liquid", "Syntax" %}

{% raw %}
```
```html
{% if nextPost %}Next Blog Post: <a href="{{ nextPost.url }}">{{ nextPost.data.title }}</a>{% endif %}
```
{% endraw %}

## Also `getCollectionItem`

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

{% codetitle "Nunjucks", "Syntax" %}

{% raw %}
```
{{ set currentPost = collections.posts | getCollectionItem(page) }}
```
{% endraw %}

* [← Back to Filters documentation.](/docs/filters/)

0 comments on commit 987613e

Please sign in to comment.