Matthew, I don't understand what's wrong with Jason's example. If DBI yields a result in the format HTML::Template understands, what's wrong with taking advantage of that? How would you change his example to make it more indirect and abstract?
I would do something like:
{ my $sql_result = $db->fetch... my @output; foreach (@{$sql_result}) { my $tmp; $tmp->{name} = $_->[0]; if ($_->[0] == 'fred') { $tmp->{selected} = 1; } push @output, $tmp; } template->param( 'some_loop' => [EMAIL PROTECTED]); }
this makes the 'some_loop' TMPL_LOOP become reasonably abstract, as used below...
The point was to move that conditional into the database query instead of doing it in perl. Your results would have been identical, except that you set 'selected' => 1 and in the example given the user set 'selected' => 'SELECTED'. But both values are true, hence you could use the example given and still have the flexibility that you require in the template.
In Postgres you could do something like this to achieve the same result:
SELECT val, text, CASE WHEN val='fred' THEN 1 ELSE 0 END as selected FROM table WHERE whatever...
Then you can still use the $sth->fetchall_arrayref( {} ) method to pull an array of hashes out of the database and pass it straight to your template, thus removing the need for the loop and the conditionals in your perl code.
Cheers,
Cees
-------------------------------------------------------
This SF.Net email is sponsored by Sleepycat Software
Learn developer strategies Cisco, Motorola, Ericsson & Lucent use to deliver higher performing products faster, at low TCO.
http://www.sleepycat.com/telcomwpreg.php?From=osdnemail3
_______________________________________________
Html-template-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/html-template-users