Go to page content

pager

Show a pager for search results.

This generates a pager as seen on the search results pages. It is used in conjunction with a paged search result.

For example, a fulltext search where the search parameters come from the query string. Note that we are using here m.search.paged and not m.search. The pager only works with results from m.search.paged.

{% with m.search.paged[{fulltext cat=q.qcat text=q.qs page=q.page}] as result %}
  <ul>
    {% pager result=result dispatch="admin_overview_rsc" qargs %}
    {% for id,score in result %}
      <li><a href="">{{ m.rsc[id].title }}</a></li>
    {% empty %}
      <li>Nothing found</li>
    {% endfor %}
  </ul>
{% endwith %}

This will show a list of titles and above that the links to the next, previous and other pages.

The generated pager code will look something like (when searching for the text “filter”):

<ul class="pager block">
<li>« prev</li>
<li class="current"><a href="/admin/overview?qs=filter&page=1">1</a></li>
<li><a href="/admin/overview?qs=filter&page=2">2</a></li>
<li><a href="/admin/overview?qs=filter&page=3">3</a></li>
<li><a href="/admin/overview?qs=filter&page=4">4</a></li>
<li class="pager-sep">…</li>
<li><a href="/admin/overview?qs=filter&page=5">5</a></li>
<li><a href="/admin/overview?qs=filter&page=2">next»</a></li>
</ul>

The pager scomp accepts the following arguments:

ArgumentDescriptionExample
resultThe result from a search.  This must be a #search_result or #m_search_result record. Note that this must be the result of a m.search.paged and not of a m.search call.result=mysearchresult
dispatchName of the dispatch rule to be used for the page urls. Defaults to the dispatch rule of the current page.dispatch="searchresult"
qargsAppend all the arguments in the HTTP request’s query string whose name starts with a 'q' as an argument to the dispatch rule.qargs
hide_single_pageWhen this argument is true, do not show the pager when the result fits on one page (e.g. the pager will be useless).hide_single_page=1
*Any other argument is used as an argument for the dispatch rule.

This page is part of the Zotonic documentation, which is licensed under the Apache License 2.0.

Comments

  • avatar

    Marco

    Posted 2 years, 1 month ago.

    hide_one_line is actually called hide_single_page.

  • avatar

    Marc Worrell

    Posted 2 years, 1 month ago.

    Thanks, I corrected the documentation.

  • avatar

    Jc

    Posted 9 months, 28 days ago.

    In the first code snippet:
    {% for id,score in result %}

    should read:
    {% for score,id in result %}
    ?

    (inversion)