From 987613e23768b78a767d80f0329611008fe7a905 Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Wed, 12 Feb 2020 08:22:45 -0600 Subject: [PATCH] Some cleanup for https://github.com/11ty/eleventy/issues/819 docs --- docs/filters/collection-items.md | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/docs/filters/collection-items.md b/docs/filters/collection-items.md index 1fd96e926a..4ff0343002 100644 --- a/docs/filters/collection-items.md +++ b/docs/filters/collection-items.md @@ -2,10 +2,11 @@ eleventyNavigation: parent: Filters key: Next or Previous Collection Item Filters + title: 'get*CollectionItem 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. @@ -21,7 +22,7 @@ eleventyNavigation: {% codetitle "Liquid", "Syntax" %} {% raw %} -``` +```liquid {% assign previousPost = collections.posts | getPreviousCollectionItem: page %} {% assign nextPost = collections.posts | getNextCollectionItem: page %} ``` @@ -29,16 +30,32 @@ eleventyNavigation: 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: {{ previousPost.data.title }}{% endif %} ``` {% endraw %} +{% codetitle "Nunjucks, Liquid", "Syntax" %} + {% raw %} -``` +```html {% if nextPost %}Next Blog Post: {{ nextPost.data.title }}{% 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/) \ No newline at end of file