this is foo.tmpl:my $dbh =DBI->connect( "dbi:$dbidriver(RaiseError=>1,Taint=>1):dbname=$dbname;host=$d +bhost", "$dbusername", "$dbpassword", ); my $statement= "select name from names"; my $sth = $dbh->prepare($statement); $sth->execute(); ##grab all rows as array ref my $site = $sth->fetchall_arrayref; $sth->finish; $dbh->disconnect; my %stuff; ##push everything into a hash foreach my $site_in ( @{$site} ) { push @{ $stuff{view} }, { name => $site_in->[0], }; } #load file my $template = HTML::Template->new( filename => catfile( foo.tmpl ), die_on_bad_params => 0 ); #load in hash $template->param( {%stuff} ); #print out print $template->output;
sorry if anything catches n breaks, i had to pull a lot of this out of some subroutines i used to break up the workload<table> <tr><td>name</td></tr> <tmpl_loop name=view> <tr> <td><tmpl_var name=name></td> </tr> </tmpl_loop>
In reply to Re: HTML::Template, DBI and <TMPL_LOOP>'s
by drfrog
in thread HTML::Template, DBI and <TMPL_LOOP>'s
by jdtoronto
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |