Re: [Templates] hashes and loops
[prev]
[thread]
[next]
[Date index for 2004/10/19]
--5oH/S/bF6lOfqCQb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
* Brandon Hall <brandonh.hall at gmail.com> [2004/10/19 12:03]:
> I've been attempting to create a data structure to store a list of
> emails and display them in the template. I think my problem is in the
> data structure, but I haven't been able to get it right. If someone
> could correct my code, I think I can figure the rest out.
>=20
> Here is how things look. The problem must be in my 'push' line below
> or in how i pass it to TT2.
I see a couple of things. First:
> my $file =3D 'show_company.tpl';
> my $vars =3D {
> message =3D> "Hello World\n",
> emaillist =3D> @emails
> };
You'll need to do:
my $vars =3D {
message =3D> "Hello World\n",
emaillist =3D> \@emails
};
For the below to work:
> [% FOREACH email IN emaillist %]
> <tr >
> <td >[% email.from %]</td>
> <td >[% email.to %]</td>
> <td >[% email.subj %]</td>
> <td >[% email.date %]</td>
> </tr>
> [% END %]
You'll need to change the push to be:
push @emails, {
from =3D> "fred",
to =3D> "wilma",
subj =3D> $subj,
date =3D> "today"
};
I.e., push a hashref instead of an arrayref of a hashref. That should
get you going...
(darren)
--=20
Blessed are the pessimists, for they test their backups.
--5oH/S/bF6lOfqCQb
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
iD8DBQFBdWdNzsinjrVhZaoRAm7nAJ98iFBi+ZpdTSx+Tq4jU6DJ74iJjgCePnUr
TzSvStyUDOPmo8pJayF00WU=
=WNbt
-----END PGP SIGNATURE-----
--5oH/S/bF6lOfqCQb--
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates
 |
(message missing)
|