in reply to Display Database table with CGI and HTML::Template

Dear god. Did you read the docs at all? Don't do what you think you want to do. Do this:
my $ht = new HTML::Template(filename=>'main.tmpl'); my $db_data=print(); $ht->params(db_data=>$db_data,%stuff); print $ht->output; sub print() { my $ht = new HTML::Template(filename=>'database_info.tmpl'); @foo=$dbh->do("select * from *"); # ok so it's not even vaugely lega +l. do yer own db code $ht->params(dbstuff=>@foo); return $ht->output; #probably not optimal }
In other words, don't do html in the sub, just have the sub initialize another template and then return the template output or the template object.

Replies are listed 'Best First'.
Re: Re: Display Database table with CGI and HTML::Template
by orkysoft (Friar) on Oct 29, 2003 at 22:44 UTC

    I think your example is too complicated. It made me look twice, so anyone unfamiliar with HTML::Template will likely not understand it at all. You're actually using a template and inserting its output into another template. Pretty confusing.

    A simpler method would be to use a TMPL_LOOP for the table of data entries, and put the actual data in a suitable data structure for HTML::Template to make a nice table in the TMPL_LOOP.

    On second thought, that might not be much simpler at all, since it requires understanding of complicated data structures.

    --

    Morbo: "Windmills do not work that way!"