Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

HTML::Template with HTML::Pager

by flyby (Novice)
on Oct 09, 2013 at 17:32 UTC ( #1057596=perlquestion: print w/ replies, xml ) Need Help??
flyby has asked for the wisdom of the Perl Monks concerning the following question:

Hello. Long time reader first time poster.

I'm attempting to use HTML::Pager with HTML::Template. I've had good luck using HTML::Template in the past but I'm running into an issue using both together. When used together the column_names feature of HTML::Pager seems to get lost. This alone works:

my $pager = HTML::Pager->new( query => $query, column_names => \@headers, get_data_callback => $data, rows => $rows, page_size => 10, );

When used with HTML::Template the headers gets lost:

my $template = HTML::Template->new( filename => 'testing.tmpl', die_on_bad_params => 0, associate => $query, ); my $pager = HTML::Pager->new( query => $query, template => $template, column_names => \@headers, get_data_callback => $data, rows => $rows, page_size => 10, );

I suspect I need to include a TMPL_LOOP for the headers in my testing.tmpl file. The docs for HTML::Pager don't mention this and don't provide any clues as to what it might be.

If someone can point me in the right direction I'd appreciate it.

-Matt

Comment on HTML::Template with HTML::Pager
Select or Download Code
Re: HTML::Template with HTML::Pager
by keszler (Priest) on Oct 09, 2013 at 18:27 UTC
    The docs I see for HTML::Pager say:
    * new() supports several optional arguements:
    • debug - if set to 1, debugging information is warn()'d during the program run. Defaults to 0.
    • template - this is an HTML::Template object to use instead of the auto-generated HTML::Template used in Pager output. It must define the following TMPL_LOOPs and TMPL_VARs. Here's what the default template looks like, to give you an idea of how to change it to suite your purposes:
      <TMPL_VAR NAME="PAGER_JAVASCRIPT"> <FORM> <TABLE BORDER=0 BGCOLOR=#000000 WIDTH=100%> <TR><TD><TABLE BORDER=0 WIDTH=100%> <TMPL_LOOP NAME="PAGER_DATA_LIST"> <TR> <TD BGCOLOR=#ffffff><TMPL_VAR NAME="PAGER_DATA_COL_0"></TD> <TD BGCOLOR=#ffffff><TMPL_VAR NAME="PAGER_DATA_COL_1"></TD> <TD BGCOLOR=#ffffff><TMPL_VAR NAME="PAGER_DATA_COL_2"></TD> <!--- depends on number of rows in data - so should your rep +lacement! --> </TR> </TMPL_LOOP> <TR><TD BGCOLOR=#DDDDDD COLSPAN=3 ALIGN=CENTER> <TMPL_VAR NAME="PAGER_PREV"> <TMPL_VAR NAME="PAGER_JUMP"> <TMPL_VAR NAME="PAGER_NEXT"> </TD></TR> </TABLE> </TABLE> <TMPL_VAR NAME="PAGER_HIDDEN"> </FORM>
      . . .

      That's what the documentation says. I'm looking for what it doesn't seem to say.

      PAGER_DATA_LIST gives you the table data with no columns names. You can add the headers in by using the column_names feature. That works just fine when using HTML::Pagers built in template but I can't get it to work when using it with HTML::Template. That's the part I'm missing.

      Seems like there should be a TMPL_LOOP for the headers. Something like:

      <TR> <TMPL_LOOP NAME="PAGER_DATA_HEADERS"> <TH BGCOLOR=#ffffff><TMPL_VAR NAME="HEADER"></TH> </TMPL_LOOP> </TR> <TMPL_LOOP NAME="PAGER_DATA_LIST"> <TR> <TD BGCOLOR=#ffffff><TMPL_VAR NAME="PAGER_DATA_COL_0"></TD> <TD BGCOLOR=#ffffff><TMPL_VAR NAME="PAGER_DATA_COL_1"></TD> </TR> </TMPL_LOOP>

      That or the headers are passed to HTML::Template under a different array ref and HTML::Template is used to print out the headers.

      Thanks for taking the time to look

      -Matt

        Is your $data hash or array? The source for HTML::Pager does:
        # fill in the template if ($args_type eq 'ARRAY') { # handle array case my @pager_list; if (defined($self->{column_names})) { my %row; my $x = 0; foreach my $col_name (@{$self->{column_names}}) { $row{"PAGER_DATA_COL_$x"} = "<B>$col_name</B>"; $x++; } push(@pager_list, \%row); } foreach my $rowRef (@{$self->{data}}) { my %row; my $x = 0; foreach my $value (@{$rowRef}) { $value = '' unless (defined($value)); $row{"PAGER_DATA_COL_$x"} = $value; $x++; } if ($x) { push(@pager_list, \%row); } } $template->param('PAGER_DATA_LIST', \@pager_list); } else { # handle the hash case $template->param(PAGER_DATA_LIST => $self->{data}); }
        which at first glance appears to ignore $self->{column_names} in the hash case.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1057596]
Approved by keszler
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2014-12-27 03:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls