question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to paginate collection data?

See original GitHub issue

I’ve set up some collections, and have indices which I’d like to paginate over the resulting data. I was expecting to be able to use the following template:

---
layout: layouts/default
title: 'Journal'
pagination:
  data: collections.posts
  size: 8
permalink: '/journal/page/{{ pagination.pageNumber }}.html'
---
{% for item in pagination.items %}
  {% include "item/post" %}
{% endfor %}

I might have misunderstood this feature, but is it possible to use collection data as a basis for pagination?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:17 (13 by maintainers)

github_iconTop GitHub Comments

3reactions
ajmalafifcommented, Dec 30, 2018

To answer your second question @paulrobertlloyd, the permalink front matter key can use template syntax (including if statements). I’ve added a test for this in the test suite, but the following will work:

---
pagination:
  data: items
  size: 2
items:
  - item1
  - item2
  - item3
  - item4
permalink: paged/{% if pagination.pageNumber > 0 %}page-{{ pagination.pageNumber }}/{% endif %}index.html
---

hey I am still struggling to make paged paginations. Is there an example repo or an output of what this code does? I tried it but it doesn’t do what I thought it would. Thanks!

1reaction
cfjedimastercommented, Oct 27, 2019

And it already is. Sigh. Stupid me not CTRL+F on the page. Sorry for the noise!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can i paginate laravel collection? - Stack Overflow
It is because paginate is Builder method, not collection. You need to create paginator manually, how described here ...
Read more >
Database: Pagination - The PHP Framework For Web Artisans
The paginate method counts the total number of records matched by the query before retrieving the records from the database. This is done...
Read more >
Laravel: How to Paginate Collection | by Sam Ngu | Medium
Laravel supports eloquent model pagination out of the box, but not custom collection. This quick tutorial will show you an easy way to...
Read more >
Paginate data with query cursors | Firestore | Firebase - Google
Paginate queries by combining query cursors with the limit() method. For example, use the last document in a batch as the start of...
Read more >
get data from Pagination - Laravel.io
You can access data object via array index. {{ $users[0]->name }}. but why? Last updated 7 months ago ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found