My template is like so:my %trial_hash = ( ABC => "john", DEF => "mike", );
And the code I'm trying to use to populate is:my $tmpl = HTML::Template->new(scalarref => \ <<EO_TMPL <!DOCTYPE HTML> <html><head><title>Table</title></head> <body> <table><thead> <tr><TMPL_LOOP TH><th><TMPL_VAR CELL></th></TMPL_LOOP></tr> </thead> <tbody><TMPL_LOOP TD><td><TMPL_VAR CELL></td></TMPL_LOOP> </tbody></table></body></html> EO_TMPL );
The output is$tmpl->param( TH => [ map { CELL => $_ }, qw( Type Value ) ], TD => [ map { CELL => $_ }, (each %trial_hash), ], );
So it's only using one value from the trial hash. I assume that the problem is I need another loop to go through each key value pair of the hashes. So if I put in another loop for the rows:<!DOCTYPE HTML> <html><head><title>Table</title></head> <body> <table><thead> <tr><th>Type</th><th>Value</th></tr> </thead> <tbody><td>ABC</td><td>john</td> </tbody></table></body></html>
then im sure this way to populate:<tbody><TMPL_LOOP TR><tr> <TMPL_LOOP TD><td><TMPL_VAR CELL></td></TMPL_LOOP> </tr></TMPL_LOOP> </tbody></table></body></html>
Is completely wrong! Also, I dont know how many key/val pairs are going to be in the hash. How would I go about populating this? The data structures required to populate templates are really confusing me. I've been reading guides but cant seem to get it into my head. Any pointers are greatly appreciated!TR => [ { TD => [ map { CELL => $_ }, (each %trial_hash) ] }, { TD => [ map { CELL => $_ }, (each %trial_hash) ] }, ],
In reply to Populating a html template problem by mavericknik
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |