paginate
Allows to paginate an array of objects. Inside the paginate
tag a paginate
object will be available.
Accepts the following arguments:
object_array
an Array of objects, for example site.pages
. (Required)
per_page
amount of items shown per page. (Not required, default: 10)
window_size
how many pages should be visible from the current page. E.g. if the current page is 5, and window size is 2, the pages available will be 3, 4, 5, 6, 7. Note that the first and the last page are always visible. (Not required, default: 3)
pagination_name
The name of the url parameter that is used to determine the current pagination number. This allows to paginate multiple arrays of objects. (Not required, default: “page”)
The following code will paginate all projects of the site. On each page, 2 projects will be available.
Paginate object
Inside the paginate
block, a paginate
object is available with the following attributes.
current_page
: the current page, a number.items
: an array of items in the slice of the inputobject_array
corresponding to the current page.page_count
: the number of pages.pages
: an array of objects representing the pagination pages. All objects inpages
have the attributesurl
(returning the url of a pagination page, e.g. /this-url?page=3),index
(the pagination page’s index number),is_link
(whether the pagination page is a link or not).is_link
returns false at the current pagination page or if the page falls outside thewindow_size
(in which case it’s merely a ‘…’).next
: represents the next pagination page. Also hasurl
,index
andis_link
attributes.previous
: represents the previous pagination page. Also hasurl
,index
andis_link
attributes.
Example Pagination
This is a typical pagination example. The important part is using the pagination_page.is_link and check the weird ellipsis html entity.
This allows for proper active and disabled styling.