Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Feb 12, 2020
1 parent ec5f3d7 commit f673522
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions docs/filters/collection-items.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
eleventyNavigation:
parent: Filters
key: Next or Previous Collection Item Filters
order: 4
excerpt: 'Get next or previous collection items for easy linking.'
---
# `getNextCollectionItem` and `getPreviousCollectionItem` Universal Filters

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

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

{% raw %}
```
{{ set previousPost = collections.posts | getPreviousCollectionItem(page) }}
{{ set nextPost = collections.posts | getNextCollectionItem(page) }}
```
{% endraw %}

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

{% raw %}
```
{% 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:

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

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

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

0 comments on commit f673522

Please sign in to comment.