-
-
Notifications
You must be signed in to change notification settings - Fork 496
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 paginated context #280
Comments
A bump from me - it would be super useful if the |
If I understand you correctly, what you are trying to do should be achievable with the current Are you saying you want the first/next/previous/last page’s |
Hi @zachleat. It's been a while since I've looked at this. Looking at the |
Pagination chunks the data into pages. For example, if I have a collection of blog posts and want to display links to the next/previous blog posts in the collection, there’s no easy way to do this via pagination. I mean, you easily get access to the URL for the previous and next page, but not anything about the actual items (e.g. if you want to show the Blog Post title in the link). You would need to iterate over the collection, which is more work than you should have to do (imo). |
@zachleat I'm not sure we're on the same page, but it might be a moot point. If in my paginated page I have this in my frontmatter:
On a given page, the value of In a parent template which doesn't know the alias I'm using in my source page template (where pagination is defined), I'm trying to get the value of FWIW, I have a filter* I use to look up post data via url: exports.filterPostsByUrl = function(items, slug, exactMatch=false) {
var output = items.filter( item => {
if (exactMatch==false && (typeof item.url === 'string' || item.url instanceof String)) return item.url.includes(slug)
if (exactMatch==true && (typeof item.url === 'string' || item.url instanceof String)) return item.url == slug
else return false
})
// Return false if no items found
return (output && output.length > 0) ? output : false
} *There's a good chance I copied this from someone else. |
Ah right on—thanks for clarifying. Regardless of whether you intended to or not, you’ve exposed another limitation with pagination that I will fix 😀.
|
@zachleat Awesome! Yes |
Docs added in 11ty/11ty-website@322c5b2 |
Forgive me if this is a bit confusing.
I'm working on some paginated pages - essentially tag pages. For each, I'd like to be able to get the first 'item' in that page's collection. The catch is I'm doing this from a parent template that doesn't know the alias used by the paginated page - so can't can't just use the alias.
The data available in
data.pagination
({ data: 'collections.byFoo', size: 1, alias: 'foo' }
) doesn't give me enough to work on to get the latest item.Ultimately I want to be able to call
collections[pagination][key][0]
to get the latest item - I can derivepagination
, but it the default data doesn't tell me what foo is a the time it's called.Is it possible actual value of
foo
? I know it's available by callingfoo
- but I'm using the alias feature quite a lot.The best I've thought of so far is to use this in the frontmatter:
This feels rather awkward.
Related, it would be helpful if more data about the current page were available to that page. Could the contents of the
page
object mirror the contents ofcollection.foo.data
? Or am I missing something?Right now, to work out if I'm on a paginated page I'm iterating through all pages in collections.all, comparing fileSlugs to see if I have a match - then looking in
collection.foo.data.pagination
.The text was updated successfully, but these errors were encountered: