in reply to Perl CGI question
I use HTML::Template exclusively for my templating and works well when populating a pull-down, using its looping function. Be advised, that the loop requires a referenced AoH to work properly. Also, the <tmpl_var xxx> you use in the HTML must match the key names in your hash.
Enjoy.Perl: use HTML::Template; ...DBI connect, etc. ... my $stmt = "SELECT id, name FROM sometable"; $sth = $dbh->prepare($stmt); $sth->execute(); my $options = $sth->fetchall_arrayref({}); $template = HTML::Template->new(filename => 'form.tmpl') $template -> param(pulldown => $options); print $template->output(); HTML: <select name="names"> <option value="">Select...</option> <tmpl_loop pulldown> <option value="<tmpl)_var id>"><tmpl_var name></option> </tmpl_loop> </select>
UPDATE: fixed a couple of typos.
|
|---|