Skip to content
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

Query parameters cleared by pagination #49

Open
NicoHood opened this issue Sep 5, 2020 · 2 comments
Open

Query parameters cleared by pagination #49

NicoHood opened this issue Sep 5, 2020 · 2 comments

Comments

@NicoHood
Copy link

NicoHood commented Sep 5, 2020

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 }}">&laquo;</a></li>
    {% else %}
        <li><span>&laquo;</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>&hellip;</span></li>
        {% endif %}

    {% endfor %}
    {% if pagination.hasNext %}
        {% set url = (base_url ~ pagination.params ~ pagination.nextUrl ~ '?' ~ uri.query())|replace({'//':'/'}) %}
        <li><a rel="next" href="{{ url }}">&raquo;</a></li>
    {% else %}
        <li><span>&raquo;</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!

@mahagr
Copy link
Member

mahagr commented Sep 14, 2020

Just a note:

There are new pagination classes which already support this:
https://github.com/getgrav/grav/tree/develop/system/src/Grav/Framework/Pagination

@NicoHood
Copy link
Author

Wouldnt it make sense to integrate such into the quark theme?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants