rlb3 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use warnings; use lib qw /./; use CGI; use Data; #Class::DBI use Template; use Tie::Cycle; my $q = CGI->new; my $file = 'index.html'; my $tt = Template->new({ INCLUDE_PATH => 'template/' }); tie my $cycle, 'Tie::Cycle', [ qw( FFFFFF CCCCCC ) ]; my $page = $q->param('page') || 1; my $pager = Data->pager(5,$page); my @data = $pager->retrieve_all; my $vars = { data => \@data, pager => $pager, cycle => $cycle }; print $q->header; $tt->process($file, $vars) || die "Template process failed: ", $tt->error(), "\n"; BEGIN TEMPLATE----------------------------------- <html> <head> <title></title> </head> <body> <table width="75%" border="0"> <tr> <th> </th> <th> Question 1 </th> <th> Question 2 </th> <th> Question 3 </th> <th> Date </th> </tr> [% FOREACH line = data %] <tr bgcolor="#[% cycle %]"> <td align="center"> [% loop.count %] </td> <td align="center"> [% line.one %] </td> <td align="center"> [% line.two %] </td> <td align="center"> [% line.three %] </td> <td align="center"> [% line.stamp %] </td> <td align="center"> <a href="delete.pl?id=[% line. +id %]">DELETE</a> </td> </tr> [% END %] </table> [% IF pager.previous_page %] <a href="index.pl?page=[% pager.previous_page %]">prev [% page +r.entries_per_page %]</a> | [% END %] [% IF pager.next_page %] <a href="index.pl?page=[% pager.next_page %]">next [% pager.e +ntries_per_page %]</a> [% END %] </body> </html>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: Tied Variables in the Template Toolkit
by merlyn (Sage) on Feb 24, 2004 at 03:37 UTC | |
by rlb3 (Deacon) on Feb 24, 2004 at 04:08 UTC | |
by Anonymous Monk on Aug 24, 2004 at 13:15 UTC | |
by dragonchild (Archbishop) on Aug 24, 2004 at 13:25 UTC | |
|
Re: Tied Variables in the Template Toolkit
by perrin (Chancellor) on Feb 24, 2004 at 03:14 UTC |