Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access page variable in pagination before filter #932

Open
joshwalsh opened this issue Feb 13, 2020 · 0 comments
Open

How to access page variable in pagination before filter #932

joshwalsh opened this issue Feb 13, 2020 · 0 comments

Comments

@joshwalsh
Copy link

I have a collections.postsByCategory which takes my collections.posts and returns a 2 dimensional array of those posts grouped by the fileSlug of the associated category.

This works great to build a category page that loops through all the posts in that category, but I'm struggling to figure out how to paginate this collection since it depends on passing in the fileSlug of the current loaded page (the category).

Specifically, I'm trying to use a before in order to return just the subset of the array I need, but this fails because I don't have access to the page variable in the scope of that before in order to get the current pages fileSlug.

Am I going about this wrong?

---js
{
  layout: "default",
  pagination: {
    data: "collections.postsByCategory",
    size: 10,
    alias: "posts",
    before: function(data) {
      return data[page.fileSlug];
      }
  }
}
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
1 participant