On Fri, May 21, 2004 at 12:39:04AM -0400, leegold wrote: > For the past couple of days I have been trying to understand* how to > use a paginator in Perl. I am learning template toolkit because it > seems a lot of paginator modules use the toolkit. So ie. 20 > results/page w/back and forward links. > > What I need is very simple working code - if only I had the > simplist of real working code I could do this - just a working > example. I've looked everywhere on the web w/no luck. No working > examples on the web(?!) > > I would be grateful again for a *simple* real life working example - > the data file, the Perl file, the template file - wouldn't that be it?
Here's a simple example using Template::Plugin::Page (which is just a wrapper around Data::Page). We'll use the Datafile plugin to store our data. numbers.dat ----------- id : name : description 1 : one : number one 2 : two : the second number 3 : three : a third number 4 : four : number, the fourth 5 : five : numero cinco 6 : six : six (not sex) 7 : seven : lucky for some 8 : eight : ate 9 : nine : number nine, number nine page.tt ------- [% USE numbers = datafile('numbers.dat') -%] [% USE page = Page(numbers.size, 4, currpage) -%] Page [% page.current_page %] of [% page.last_page %] Entries [% page.first %] to [% page.last %] of [% page.total_entries %] [% FOREACH num = page.splice(numbers) -%] [% num.id %] [% num.name | format('%-8s') %] [% num.description %] [% END -%] The template takes one input variable (currpage). For this simple example we can pass that in using tpage. So, for example: $ tpage --define currpage=2 page.tt Page 2 of 3 Entries 5 to 8 of 9 5 five numero cinco 6 six six (not sex) 7 seven lucky for some 8 eight ate $ Does that help? Dave... -- Stab a sorry heart With your favourite finger _______________________________________________ templates mailing list [EMAIL PROTECTED] http://lists.template-toolkit.org/mailman/listinfo/templates
