-
Notifications
You must be signed in to change notification settings - Fork 641
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
FR: Pass query results to paginate tag #4120
Comments
This mostly defeats the point of pagination, but we just released Craft 3.1.22 which adds a {% set query = craft.entries()
.section('shops')
.orderBy('shopName ASC') %}
{% set allShops = query.all() %}
{% set shopsPerPage = 10 %}
{% set offset = (craft.app.request.pageNum - 1) * shopsPerPage %}
{% set pageShops = allShops|slice(offset, shopsPerPage) %}
{% set paginator = create('craft\\db\\Paginator', [query, {
pageSize: shopsPerPage,
currentPage: craft.app.request.pageNum,
pageResults: pageShops
}]) %}
<!-- create the map -->
{% for shop in allShops %}
...
{% endfor %}
<!-- page results -->
{% for shop in pageShops %}
...
{% endfor %}
<!-- pagination navigation -->
{% set pageInfo = create('craft\\web\\twig\\variables\\Paginate').create(paginator) %}
Page: {{ pageInfo.currentPage }}
First Page: {{ pageInfo.firstUrl }}
Last Page: {{ pageInfo.lastUrl }}
Prev Page: {{ pageInfo.prevUrl }}
Next Page: {{ pageInfo.nextUrl }} If it were me, I’d just opt for a second query on the page, maybe within some |
Nice! I'll make sure to test out your solution. Thanks for the quick reply. Awesome work as always 🤗 |
I'm trying to do something similar but am getting and error when I try to set up the pageInfo.
|
@simeon-smith |
@brandonkelly, I was following the code in your example. Is this no longer available? |
Whoops, that should have been |
Description
I sometimes have pages where I need a list of items, both paginated and not paginated. For example: a page with a list of shops. I would like to have
At the moment I have to do this in 2 seperate queries:
The text was updated successfully, but these errors were encountered: