-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

* Brad Nicholson <brad at quadrant.net> [2003-08-12 08:19]:
> 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 

Any reason you're not using a hash for these?

Here's a simple way to do what your examples do:

> for ($j = 1; $j<10; $j++)
> {
>     $vars{'key_val_'.$j} = "Value  $j";
> }


  $vars{'stuff'} = { };
  for ($j = 1; $j<10; $j++)
  {
      $vars{'stuff'}->{$j} = "Value  $j";
  }

This sets up:

  (
    stuff => { 1 => "Value 1",
               2 => "Value 2",
             }
  )

and so on.

> [% count = 1 %]
> 
> [% WHILE total <= count  %]
> 
> Current value  = [% 'key_val_' count %]<br>
> 
> [% count = count + 1 %]
> [% END %]

  [% FOREACH item = stuff.keys %] 
  Current value = [% stuff.$item %]<br>
  [% END %]

Of course, if your keys really are numbers, as your example implies, you
could use an array:

  $vars{'mystuff'} = [ ];
  for ($j = 1; $j<10; $j++)
  {
      $vars{'mystuff'}->[$j] = "Value  $j";
  }

  [% FOREACH item = stuff %]
  Current value = [% stuff %]<br>
  [% END %]

(darren)

- -- 
You know the great thing about TV? If something important happens
anywhere at all in the world, no matter what time of the day or night,
you can always change the channel.
    -- Jim Ignatowski
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
Comment: This message is digitally signed and can be verified for authenticity.

iD8DBQE/OOA0zsinjrVhZaoRApALAJ4lCtH1aBAbb0BS7+zIGKlYG++vJQCfVQDk
kMB2AnhUsVzZwsALli5E+BI=
=Py/3
-----END PGP SIGNATURE-----

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

Reply via email to