Skip to content

Paginating Global Data #2831

Answered by pdehaan
aaronstezycki asked this question in Q&A
Feb 28, 2023 · 2 comments · 13 replies
Discussion options

You must be logged in to vote

I think if you search the issues for "pagination" there should be a few threads for double-pagination or multi-pagination which might have some ideas. I did find #332

In your case, I'd probably just flatten the stock.json file before paginating. Here's a quick prototype using the before() callback:

---
# search.njk
# see search.11tydata.js for front matter.
---

<h1>{{ vehicle.brand }}</h1>
<p>{{ vehicle.range }}<p>
// stock.11tydata.js
module.exports = {
  pagination: {
    data: "stock",
    size: 1,
    alias: "vehicle",
    before(data) {
      return data.reduce((vehicles, vehicle) => {
        for (const stock of vehicle.stock) {
          vehicles.push({ brand: vehicle.brand, ...stock

Replies: 2 comments 13 replies

Comment options

You must be logged in to vote
10 replies
@pdehaan
Comment options

@pdehaan
Comment options

@aaronstezycki
Comment options

@pdehaan
Comment options

@aaronstezycki
Comment options

Answer selected by aaronstezycki
Comment options

You must be logged in to vote
3 replies
@aaronstezycki
Comment options

@pdehaan
Comment options

@aaronstezycki
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants