On Sat, 16 Jul 2005, John Smith wrote:

> I am new to using Template and don't quite understand
> variable notation. Suppose I have the following program:
>
> #!perl
> use Template;
> my $tt = Template->new();
> my $data =
> {
>   d1 => [ 1, 3 ],
>   d2 => { 0 => "zero", 1 => "one", 2 => "two", 3 => "three" }
> };
> $tt->process("foo.tt", $data);
>
>
> and the following data file (foo.tt):
>
> [% FOREACH id = d1 %]
>   id is [% id %]
>   [% d2.id %]
> [% END %]
>
> The output of id works as expected. But I am trying
> to use id as a key into d2 and I am not getting
> it. Obviously I am misunderstanding this. How are
> you supposed to do this sort of thing?

I think you want:

  [% d2.$id %]

The way you have it written, it's trying to find $d2->{ id }, as
opposed to $d2->{ 0 }, $d2->{ 1 }, $d2->{ 2 } or $d2->{ 3 }.

Hope that helps.

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