Hi Phil,

On Friday 21 December 2001 12:30, Phil Taylor wrote:
> Is there a standard approach to creating SELECT lists with the
> HTML::Template module?
 
> I have a problem creating SELECT lists with HTML::Template. I can create
> the list no problem using the LOOP construct but I want to set the SELECTED
> item in the list based on what they may have previously selected if the
> associated entry form is re-displayed. I don't see any way that the
> HTML::TEMPLATE module can handle this? My only current alternative is to
> build the entire HTML <SELECT>...</SELECT> component in my application and
> pass this as a template parameter. I'm not too happy with this as I start
> to lose the separation between business logic and presentation.
 
> I would be really grateful for any thoughts on this.
> 

This is how I do it:

<SELECT multiple NAME=<TMPL_VAR NAME=QPARAM1> SIZE=6>
   <TMPL_LOOP NAME=LOOP1>
      <TMPL_IF NAME="SELECTED">
         <OPTION VALUE=<TMPL_VAR NAME=VALUE> SELECTED><TMPL_VAR NAME=DISPLAY>
      <TMPL_ELSE>
         <OPTION VALUE=<TMPL_VAR NAME=VALUE>><TMPL_VAR NAME=DISPLAY>
      </TMPL_IF>
   </TMPL_LOOP>
</SELECT>

And this is the associated Perl bit, the 'SELECTED' hash key becomes either 1 
pr 0 depending on whether the associated query parameter exists, this then 
determines which part of LOOP1 is executed in the template.

$template->param(
              [...]

              LOOP1 => [
                        {'VALUE' => 'all', 'DISPLAY' => 'all', 'SELECTED' => 
$query->param('profile_name') eq "all" ? 1 : 0 },
                        {'VALUE' => 'student', 'DISPLAY' => 'student',  
SELECTED' => $query->param('profile_name') eq "student" ? 1 : 0 },
                        {'VALUE' => 'coord', 'DISPLAY' => 'co\366rdinator', 
'SELECTED' => $query->param('profile_name') eq "coord" ? 1 : 0},
                        {'VALUE' => 'admin', 'DISPLAY' => 'administrator', 
'SELECTED' => $query->param('profile_name') eq "admin" ? 1 : 0},
                       ],
                   QPARAM3 => "profile_name",
                   CAT3 => "Profile",
 
              [...]
              );


Kind regards,

Martijn

-- 
+----------------------------------+
| Martijn van den Burg             |
| ASML, CS PPC Inform@tion Systems |
| Voice: +31 (0)40 268 3856        |
+----------------------------------+

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to