grav-plugin-pagination
grav-plugin-pagination copied to clipboard
Query parameters cleared by pagination
I am using query parameters www.website.com/page:1?param=true for additional filtering. But the current pagination template removes those queries. It would be nice to integrate this into the plugin.
This is my solution:
{% set pagination = pagination|default(page.collection.params.pagination) %}
{% set base_url = base_url|default(page.url) %}
{% if pagination|length > 1 %}
<ul class="pagination">
{% if pagination.hasPrev %}
{% set url = (base_url ~ pagination.params ~ pagination.prevUrl ~ '?' ~ uri.query())|replace({'//':'/'}) %}
<li><a rel="prev" href="{{ url }}">«</a></li>
{% else %}
<li><span>«</span></li>
{% endif %}
{% for paginate in pagination %}
{% if paginate.isCurrent %}
<li><span class="active">{{ paginate.number }}</span></li>
{% elseif paginate.isInDelta %}
{% set url = (base_url ~ pagination.params ~ paginate.url ~ '?' ~ uri.query())|replace({'//':'/'}) %}
<li><a href="{{ url }}">{{ paginate.number }}</a></li>
{% elseif paginate.isDeltaBorder %}
<li class="gap"><span>…</span></li>
{% endif %}
{% endfor %}
{% if pagination.hasNext %}
{% set url = (base_url ~ pagination.params ~ pagination.nextUrl ~ '?' ~ uri.query())|replace({'//':'/'}) %}
<li><a rel="next" href="{{ url }}">»</a></li>
{% else %}
<li><span>»</span></li>
{% endif %}
</ul>
{% endif %}
Maybe it would make sense to add a variable to enable this new feature to not break older themes. Feel free to use that code!
Just a note:
There are new pagination classes which already support this: https://github.com/getgrav/grav/tree/develop/system/src/Grav/Framework/Pagination
Wouldnt it make sense to integrate such into the quark theme?