4

I'm looking to paginate and array with multiple filters.

The current url would be: www.example.com/search?filter=shorts&type=leather&brand=sams

Clicking on the next next link returns: www.example.com/search/p2 effectively removing the search params.

Is there a way to paginate the full url without removing the search params?

{% paginate test.limit(4) as entries %}
    {% for entry in entriesOnPage %}
        <article>
            <h1>{{ entry.title }}</h1>
            {{ entry.body }}
        </article>
    {% endfor %}

    {% if paginate.prevUrl %}
        <a href="{{ paginate.prevUrl }}">Previous Page</a>
    {% endif %}

    {% if paginate.nextUrl %}
        <a href="{{ paginate.nextUrl }}">Next Page</a>
    {% endif %}
{% endpaginate %}
6

Try using this (completely untested):

{% if paginate.prevUrl %}
    <a href="{{ paginate.prevUrl }}?{{ craft.request.getQueryStringWithoutPath() }}">Previous Page</a>
{% endif %}

{% if paginate.nextUrl %}
    <a href="{{ paginate.nextUrl }}?{{ craft.request.getQueryStringWithoutPath() }}">Next Page</a>
{% endif %}

Update:

The above will only work once Craft 2.3 comes out.

In the meantime, it's a bit sketchy, but you can open up craft/app/variables/HttpRequestVariable.php and add this method:

public function getQueryStringWithoutPath()
{
    return craft()->request->getQueryStringWithoutPath();
}

And it should work. But please be aware that file could be overwritten by a 2.2 build release at any point during an auto-update and your template would break.

|improve this answer|||||
  • Thanks but that didn't work. Throws this error: 'Method "getQueryStringWithoutPath" for object "Craft\HttpRequestVariable" does not exist' – Kyle Sep 15 '14 at 21:28
  • Gah... just realized that got added to the unreleased Craft 2.3. – Brad Bell Sep 15 '14 at 21:30
  • Updated answer. – Brad Bell Sep 15 '14 at 21:35
  • Hacking the core? That's some back-alley advice right there Brad. ;) – Lindsey D Sep 15 '14 at 22:38
  • 2
    HACK THE PLANET – Brad Bell Sep 15 '14 at 22:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.