In most Craft projects I do I'll create a pagination include file so anything I need that requires pagination, I can just include that and I get the same pagination pattern anywhere within my site when I need it.
While you do have to set the country attribute with each link, sometimes it might get a little tedious to do this manually or you may expand your attributes to include other options, like ?country=123&distance=50
.
This is where Craft's craft.request.getQueryStringWithoutPath()
comes into play. In Craft 3 this has been changed to craft.app.request.queryStringWithoutPath
. But you could do something like this:
{% if craft.request.getQueryStringWithoutPath() %}
{% set queryString = "?" ~ craft.request.getQueryStringWithoutPath() %}
{% endif %}
<a href="{{ paginate.prevUrl }}{% if queryString is defined %}{{ queryString }}{% endif %}">Previous</a>
Then no matter what URL attributes you have, they'll always be included within your pagination links.
<a href="{{ pageInfo.prevUrl }}?country=123">Previous Page</a>