Mojolicious::Plugin::TagHelpers::Pagination - Pagination Helper for Mojolicious
# Mojolicious $app->plugin('TagHelpers::Pagination' => { separator => ' ', current => '<strong>{current}</strong>' }); # Mojolicious::Lite plugin 'TagHelpers::Pagination' => { separator => ' ', current => '<strong>{current}</strong>' }; # In Templates %= pagination(2, 4, '?page={page}' => { separator => "\n" }) # <a href="?page=1" rel="prev"><</a> # <a href="?page=1">1</a> # <a rel="self"><strong>2</strong></a> # <a href="?page=3">3</a> # <a href="?page=4">4</a> # <a href="?page=3" rel="next">></a>
Mojolicious::Plugin::TagHelpers::Pagination helps you to create pagination elements in your templates, like this:
< 1 ... 5 [6] 7 ... 18 >
Mojolicious::Plugin::TagHelpers::Pagination inherits all methods from Mojolicious::Plugin and implements the following new one.
# Mojolicious $app->plugin('TagHelpers::Pagination' => { separator => ' ', current => '<strong>{current}</strong>' }); # Or in your config file { 'TagHelpers-Pagination' => { separator => ' ', current => '<strong>{current}</strong>' } }
Called when registering the plugin.
All parameters can be set either as part of the configuration file with the key TagHelpers-Pagination or on registration (that can be overwritten by configuration).
TagHelpers-Pagination
# In Templates: %= pagination(4, 6 => '/page-{page}.html'); % my $url = Mojo::URL->new->query({ page => '{page}'}); %= pagination(4, 6 => $url); %= pagination(4, 6 => '/page/{page}.html', { current => '<b>{current}</b>' });
Generates a pagination string. Expects at least two numeric values: the current page number and the total count of pages. Additionally it accepts a link pattern and a hash reference with parameters overwriting the default plugin parameters for pagination. The link pattern can be a string using a placeholder in curly brackets (defaults to page) for the page number it should link to. It's also possible to give a Mojo::URL object containing the placeholder. The placeholder can be used multiple times. In case the total count of pages is unknown, a -1 can be passed and the final page is ommited for pagination.
page
-1
For the layout of the pagination string, the plugin accepts the following parameters, that are able to overwrite the default layout elements. These parameters can again be overwritten in the pagination helper.
Pattern for current page number. The {current} is a placeholder for the current number. Defaults to [{current}]. Instead of a pattern, both sides of the current number can be defined with current_start and current_end.
{current}
[{current}]
current_start
current_end
Placeholder symbol for hidden pages. Defaults to ....
...
Symbol for next pages. Defaults to >.
>
Callback for visualizing page numbers. The page number is passed as the first parameter to num_format and a returned string value is expected.
num_format
This parameter is EXPERIMENTAL and may change without warning.
Pattern for page number. The {page} is a placeholder for the page number. Defaults to {page}. Instead of a pattern, both sides of the page number can be defined with page_start and page_end.
{page}
page_start
page_end
String representing the placeholder for the page number in the URL pattern. Defaults to page.
Symbol for previous pages. Defaults to <.
<
Symbol for the separation of pagination elements. Defaults to .
Mojolicious.
https://github.com/Akron/Mojolicious-Plugin-TagHelpers-Pagination
Copyright (C) 2012-2021, Nils Diewald.
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
To install Mojolicious::Plugin::TagHelpers::Pagination, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::TagHelpers::Pagination
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::TagHelpers::Pagination
For more information on module installation, please visit the detailed CPAN module installation guide.