-
-
Notifications
You must be signed in to change notification settings - Fork 72
Pagination
Tags provides a pagination tag that can be used within buffalo plush templates. Buffalo ships with a plush helper called paginator
, which signature is as follow:
func(pagination *pop.Paginator, opts map[string]interface{}, help plush.HelperContext) (template.HTML, error) {
Usually the *pop.Paginator
is built within your buffalo action based on parameters passed in the context by calling PaginateFromParams
pop's connection method and using the pop.Paginator
from inside the resulting query, this will apply pagination from the params as well as set the instance of pop.Paginator
we need for the view.
q := tx.PaginateFromParams(c.Params())
c.Set("paginator", q.Paginator)
And then used in the view by calling the helper we mentioned in the following way:
<%= paginator(pagination) %>
This will produce page numbers based on the query results as well as next/prev links as in the following:
<ul class=" pagination">
<li class="disabled"><span>«</span></li>
<li class="active"><a href="/movements?page=1">1</a></li>
<li><a href="/movements?page=2">2</a></li>
<li><a href="/movements?page=3">3</a></li>
<li><a href="/movements?page=4">4</a></li>
<li><a href="/movements?page=5">5</a></li>
<li class="disabled"><a>...</a></li>
<li><a href="/movements?page=43">43</a></li>
<li><a href="/movements?page=2">»</a></li>
</ul>
As you may have seen, the paginator
helper function receives some options that will allow you to configure the way the pagination is generated.
- path: This is the base path for the paginator (defaults at current path).
- class: Class that should be added to the ul containing the pagination, this ul will also be added the
pagination
class from bootstrap.(defaults pagination) - showPrev: if it should show prev link (defaults true)
- previousContent: this is the content of the prev link (defaults «)
- showNext: if it should show next link (defaults true)
- nextContent: this is the content of the next link (defaults »)
- wingLength: this is the number of pages to be shown in the paginator (defaults to 5)