Giter Club home page Giter Club logo

Comments (7)

 avatar commented on June 30, 2024 1

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.

from grav-plugin-pagination.

rhukster avatar rhukster commented on June 30, 2024

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.

from grav-plugin-pagination.

inktrap avatar inktrap commented on June 30, 2024

@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.

from grav-plugin-pagination.

RosemaryOrchard avatar RosemaryOrchard commented on June 30, 2024

I would also appreciate a way to get the size of a collection without hacking around.

from grav-plugin-pagination.

webstationhq avatar webstationhq commented on June 30, 2024

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).

from grav-plugin-pagination.

webstationhq avatar webstationhq commented on June 30, 2024

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".
Since the pagination limit was set at 3, we could not get this to print "Showing 3 of 4" since

{{ page.collection | length }} 

only returns the current page. To solve it, we added this to the front matter:

content:
items: '@self.children'
    limit: '3'
    order:
        by: date
        dir: asc
    pagination: true
unpaginated:
    items: @self.children
    filter:
        published: true

and then used this code in the twig of the parent page using the blog template in the pagination.html.twig file:

<li class="page-item disabled">
       {# See issue https://github.com/getgrav/grav-plugin-pagination/issues/29 #}
       {% set fullsize = page.header.unpaginated ? page.collection('unpaginated') : page.collection %}
        <span class="page-link"  aria-hidden="true">Showing {{ page.collection | length }} of {{ 
fullsize|length }} properties</span>
        <span class="sr-only">Previous</span>

Here is the output:

Screen Shot 2020-05-23 at 12 30 36 PM

from grav-plugin-pagination.

mbirth avatar mbirth commented on June 30, 2024

It's 2021 now. Is there really no better solution as of yet?

from grav-plugin-pagination.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.