George_Sherston has asked for the wisdom of the Perl Monks concerning the following question:
But that means (AFAIK) that in the hash which I feed to my template I have to have lots ofkeys that don't do anything - i.e. to select "3 days":<select name="MinDuration"> <option value=0<TMPL_IF MINDURATION0> selected</TMPL_IF>> any <option value=1<TMPL_IF MINDURATION1> selected</TMPL_IF>> one +day <option value=2<TMPL_IF MINDURATION2> selected</TMPL_IF>> two +days <option value=3<TMPL_IF MINDURATION3> selected</TMPL_IF>> thre +e days <option value=4<TMPL_IF MINDURATION4> selected</TMPL_IF>> four + days <option value=5<TMPL_IF MINDURATION5> selected</TMPL_IF>> one +week </select>
Plus, this is ugly because there is no direct relationship between the returned value and the value I feed to my template.$my_template->param( { minduration0 => 0, minduration1 => 0, minduration2 => 0, minduration3 => 1, minduration4 => 0, minduration5 => 0, } );
And then in the script I'd have<TMPL_VAR DATEMENU>
But neither of these is quite right. The first is too cludgy in translating from submitted values to initialisation values; the seconde uses all the CGI.pm magic, but it's a two step, and it involves sending large chunks of html to HTML::Template which... feels a bit wrong. Left to my own devices I'd go with method two as the lesser evil, but I wonder if there is a cleaner way - either some clever HTML::Template wheeze, or a different templating system or... TIMTOWTDI???$my_template->param( { datemenu => popup_menu( -name => 'MinDuration', -values => [0..5], -default => 3, -labels => { 0 => ' any', 1 => ' one day', 2 => ' two days', 3 => ' three days', 4 => ' four days', 5 => ' one week', } ),
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SELECT pop-up menus in HTML::Template
by Asim (Hermit) on Jan 17, 2002 at 00:52 UTC | |
|
Re: SELECT pop-up menus in HTML::Template
by gav^ (Curate) on Jan 17, 2002 at 00:55 UTC | |
|
Re: SELECT pop-up menus in HTML::Template
by gav^ (Curate) on Jan 17, 2002 at 00:24 UTC |