Join our HiFi mailing list to receive the latest news & updates

Paginate Anything


This snippet allows you to easily paginate ANY HiFi query, no matter how complex.  Normally when you paginate something in hifi you use the "count" and "page" modifiers.  This takes care of all of that for you.

It works as a twig macro.  You tell it your query and give it the path to a row template.  It will then use that row for each of the results and then display the appropriate pagination.


No external requirements -- although this snippet won't do you any good if you're not on HiFi.



    {% import '/paginator/paginator.html' as paginator %}
    {{ paginator.paginate({
        query: {type: 'post', orderBy: '-publishedAt'},
        count: 5,
        template: '/paginator/row.html',
        paginationTemplate: '/paginator/pagination.html' 
    }) }}


To install this snippet, you just need to copy in the three files that are include in the zip.  I like to put them in a folder together to keep things organized.  I put them in '/common/paginator/'. There are three files:

  1. paginator.html: This is the primary file that contains the macro.  It is the only one of the three that is required.
  2. pagination.html: This is a default template for the "Previous" and "Next" links. You can use a different one if you like.
  3. row.html: This is a default row template. You can of course use any row template you like.

To use the snippet, call the macro as you see above.  All of the parameters are optional.  You can see the defaults by looking at paginator.html.

Typically, you'll write a query and a row template.  The row template is passed two variables: item and loop.  The item variable is the hifi object for a particular row.  The loop variable is the loop variable from twig.



  1. There are no comments yet.