NAME

Template::Plugin::Bootstrap::Pagination - Produce HTML suitable for the Bootstrap pagination component

VERSION

version 0.001002

SYNOPSIS

use Template;
use Data::Page;

my $pagination_template_string = <<"EOTEMPLATE";
[%- USE Bootstrap.Pagination -%]
[%- Bootstrap.Pagination.pagination(pager = pager, uri = uri) -%]
EOTEMPLATE

my $pager_template_string = <<"EOTEMPLATE";
[%- USE Bootstrap.Pagination -%]
[%- Bootstrap.Pagination.pager(pager = pager, uri = uri) -%]
EOTEMPLATE

my $pager = Data::Page->new(42, 10, 2);
my $uri = 'http://www.example.com/blog/__PAGE__.html';
my $template = Template->new(STRICT => 1);
my $output;

my $pagination_result = $template->process(\$pagination_template_string, {
	pager => $pager,
	uri   => $uri,
}, \$output) or die $template->error();

my $pager_result = $template->process(\$pager_template_string, {
	pager => $pager,
	uri   => $uri,
}, \$output) or die $template->error();

DESCRIPTION

Template::Plugin::Bootstrap::Pagination is a plugin for Template::Toolkit which produces HTML compatible to the Bootstrap framework's pagination component.

METHODS

new

Constructor, creates a new instance of the plugin.

Parameters

This method expects its parameters as one positional parameter and an optional hash reference. The values passed in the hash reference will be used as default values, and can be overridden when calling the plugin's methods.

context

A reference to the Template::Context which is loading the plugin. This is the positional parameter.

uri

Template for the URI to use in links. Any occurrence of __PAGE__ in the URI will be replaced by the page number it should point to. Please note that the URI will be entity encoded before adding it to the generated HTML.

pager

The Data::Page object the pager should be built with.

prev_text

Text to use in the link to the previous page. Defaults to &laquo;.

next_text

Text to use in the link to the next page. Defaults to &raquo;.

offset

Offset to add to the page number. May be negative, which can be useful if the application's first page is 0, not 1. Defaults to 0.

factor

Factor to multiply the page number with. Can be useful if the application does not use pages, but offsets from eg. 0 (in that case, the factor will usually be the page size). Defaults to 1.

siblings

Number of links to display to the left and the right of the current page. Defaults to 3. Only used in "pagination".

centered

If the pager should be centered. Defaults to 0, i.e. false. Only used in "pagination".

If the pager should be right aligned. Defaults to 0, i.e. false. Only used in "pagination".

align

Don't center previous and next links, align them to the sides instead. Defaults to 0, i.e. false, so the links will be centered. Only used in "pager".

Result

The new instance.

pagination

Get HTML for a pagination. Includes a previous/next link, links to first and last page, and links to a range of pages around the current page:

< | 1 | ... | 8 | 9 | _10_ | 11 | 12 | ... | n | >

Parameters

This method expects positional parameters. See "new" for the available parameters, their description and their defaults. pager and uri are required if they have not been passed to "new" as defaults.

Result

The HTML code.

pager

Get HTML for a simple pager with only previous and next links.

Parameters

This method expects positional parameters. See "new" for the available parameters, their description and their defaults. pager and uri are required if they have not been passed to "new" as defaults.

Result

The HTML code.

SEE ALSO

AUTHOR

Manfred Stock <mstock@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Manfred Stock.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.