At 09:33 PM 12/26/01 -0800, J,L wrote:
>maybe i misled you in the previouse post let me be
>more specify. suppose i have this in a perl script :
>#################################
>my @keywords = qw(key_1 key_2 key_3);
>my @loop;
># wish could skip this foreach only do
>#$template->param('keywords' => @keywords);
># it's one more hash and array !!
>foreach (@keywords) {
>       my %result;
>       $result{'keyword'} = $_;
>       push(@loop,\%result); 
>}
>$template->param('keywords' => \@loop);
>print $template->output;
>
>in a tmpl file :
>
><P>Your search for <b><TMPL_LOOP NAME="keywords">
><TMPL_VAR NAME="keyword"></tmpl_loop></b> found bla
>bla..
>##################################
>I feel that i did too much codes just for printing the
>elements in @keywords. Comparing to this 
>print @keywords; # no HTML::Template at all....

What was wrong with this suggestion?

  $template->param( keywords_string => join ' ', @keywords );

Then in your template:

  <P>Your search for <b><TMPL_VAR keywords_string></b> bla bla


I wouldn't worry about the use of the hash though.  If you want to do it
your way in fewer lines, I suppose you could do something (untested) like:

  my %params;
  ...
  $params{keywords} =  [ map { keyword => $_ }, @keywords ] ;
  ...
  $template->param( \%params );

  <P>Your search for <b>
  <TMPL_LOOP keywords>
     <TMPL_VAR keyword>
  </TMPL_LOOP>
  </b> foo


-- 
Bill Moseley
mailto:[EMAIL PROTECTED]

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

Reply via email to