Skip to content

Commit d9c431a

Browse files
committed
Docs for pagination: let data key be a function
1 parent 52f55b6 commit d9c431a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/docs/pagination.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,28 @@ pagination:
355355

356356
The above generates a list of links but you could do a lot more. See what’s available in the [Collection documentation](/docs/collections/#collection-item-data-structure) (specifically `templateContent`). If you’d like to use this to automatically generate Tag pages for your content, please read [Quick Tip #004—Create Tag Pages for your Blog](/docs/quicktips/tag-pages/).
357357

358+
## Making `data` a function {% addedin "0.12.2" %}
359+
360+
Instead of `data` being a string, it can be a function that returns the data key. The function gets passed a single parameter containing all template data for the current page. In this way, the pagination data key can be determined dynamically.
361+
362+
{% raw %}
363+
```markdown
364+
---js
365+
{
366+
pagination: {
367+
data: function(data) {
368+
return "collections." + data.pageTopic;
369+
},
370+
size: 2
371+
}
372+
}
373+
---
374+
<!-- the rest of the template -->
375+
```
376+
{% endraw %}
377+
378+
In the above example, if the containing page has the key-value `pageTopic: ponies` in its front matter, then the pagination data key will end up being `collections.ponies`.
379+
358380
## Modifying the Data Set prior to Pagination
359381

360382
### Reverse the Data {% addedin "0.7.0" %}

0 commit comments

Comments
 (0)