On Mon, 11 Aug 2003, Brad Nicholson wrote:

> I have a series of dynamically generated variables defined in my Perl code
> which I pass through to my template, and I want to print those values in my
> template 
> 
> Here's an example of what I'm trying to do:
> 
> In in the perl code:
> 
> for ($j = 1; $j<10; $j++)
> {
>     $vars{'key_val_'.$j} = "Value  $j";
> }
> 
> 
> Which will add 
> 
> key_val_1 = Value 1
> key_val_2 = Value 2
> Ect, ect
> 
> and I need to print them out via the template, but I can't seem to find out
> how to do so
> 
> [% count = 1 %]
> 
> [% WHILE total <= count  %]
> 
> Current value  = [% 'key_val_' count %]<br>
> 
> [% count = count + 1 %]
> [% END %]
> 
> I want the output to be:
> Current value is Value 1
> Current value is Value 2
> ect, ect, ect,
> 
> 
> How do I get TT to evaluate [% 'key_val_' count %] and return the
> appropriate values?

Easy (though not perhaps as intuitive as TT3 promises to be):

  [% ${"key_val_$count"} %]

Dave

/L\_/E\_/A\_/R\_/N\_/T\_/E\_/A\_/C\_/H\_/L\_/E\_/A\_/R\_/N\
Dave Cash                              Power to the People!
Frolicking in Fields of Garlic               Right On-Line!
[EMAIL PROTECTED]                                  Dig it all.


_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to