Re: [htmltmpl] Select/option How to set "selected"?
Brought to you by:
samtregar
From: Mathew R. <mat...@re...> - 2004-05-04 03:26:54
|
> What's really neat if you do it like that is you can use DBI's=20 > fetchall_arrayref method and be really snazzy: >=20 > my $template =3D HTML::Template->new( 'filename' =3D> 'file.TMPL' ); > my $sth =3D $dbh->prepare( <<_SQL_ ); > SELECT val, > text, > (if then else to return 'selected' or '') AS selected > FROM table > WHERE whatever... > _SQL_ > $sth->execute(); > $template->param( 'OCCUPATION_LOOP' =3D> $sth->fetchall_arrayref( {} ) = ); > ## Note that the fetchall_arrayref doesn't save you computing time -- > ## it's only a shortcut and does the same thing as your loop to go > ## through the results > --- >=20 > What's neat about this, too is that it simplifies the template code, = as=20 > Puneet laid out. Except that you have now tied your SQL statement directly to HTML = syntax; in which case... what is the point of using H::T -> you could = generate HTML output faster if you created an SQL statement which = generated HTML directly. The purpose of H::T is to decopule the data from the presentation. Mathew |