-
Notifications
You must be signed in to change notification settings - Fork 20
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
Get collection|length of paginated collection #29
Comments
pagination in twig is not really the best way, i think actually this is something to look at in the Collection class itself, within the Grav core. I'm surprised there isn't a method already. I'll have to have a look. |
@rhukster since I am actively using grav and would like to use pagination and get the total number of articles … I would like to ask if there has been any progress yet?! Don't want to stress, though. |
I would also appreciate a way to get the size of a collection without hacking around. |
Quite old issue but in case someone reads it searching for a solution: I handle this issue by declaring a second collection (named "unpaginated") in the frontmatter like seen here and using it to access the full length like here. It's not beautiful but it delivers the results I need. |
We recenrly ran into this issue. As of version 1.6.25, this is still not fully solved. If there are others who would like to have access to this via twig, I am contemplating writing something in order to use a twig statement like: {% page.collection | raw_length %} To provide the actually length of self.siblings prior to pagination. Or, has this been solved and we have missed it? If so, any help is appreciated. We are fairly new to Grav (and LOVE it). |
Found another solution that seems to work well and wanted to share here Background: We have a page using the blog twig template, several subpages (posts) using the item twig template. We wanted to use pagination with a snippet of text that says "Showing page X of Y".
only returns the current page. To solve it, we added this to the front matter:
and then used this code in the twig of the parent page using the blog template in the pagination.html.twig file:
Here is the output: |
It's 2021 now. Is there really no better solution as of yet? |
I would like to get the length of the collection in a twig template.
If I have a collection of 11 pages:
and I 1) disable pagination or set the limit to 0, I can use this to get the length of a collection:
However, 2) with pagination enabled and a limit set to 10, this won't work, since the length of the collection is the current paginated collection.
So my question would be: can I (a) calculate the total number of pages somehow, (b) is the number stored in some variable which I have not found yet, or (c) should I implement a workaround (do pagination in twig), like in #13 ?
The text was updated successfully, but these errors were encountered: