Re: [Templates] hashes and loops

[prev] [thread] [next] [Date index for 2004/10/19]

From: Darren Chamberlain
Subject: Re: [Templates] hashes and loops
Date: 19:13 on 19 Oct 2004
--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)

[Templates] hashes and loops
Brandon Hall 19:03 on 19 Oct 2004

Re: [Templates] hashes and loops
Sean Kellogg 19:10 on 19 Oct 2004

Re: [Templates] hashes and loops
Brandon Hall 06:51 on 21 Oct 2004

Re: [Templates] hashes and loops
Michael 13:44 on 21 Oct 2004

Re: [Templates] hashes and loops
Michael 13:58 on 21 Oct 2004

Re: [Templates] hashes and loops
Dave Cash 13:47 on 21 Oct 2004

Re: [Templates] hashes and loops
Sean McAfee 14:34 on 21 Oct 2004

Re: [Templates] hashes and loops
Trond Michelsen 14:44 on 21 Oct 2004

Re: [Templates] hashes and loops
Mark Mills 15:22 on 21 Oct 2004

Re: [Templates] hashes and loops
Darren Chamberlain 19:13 on 19 Oct 2004

Re: [Templates] hashes and loops
Simon Wistow 20:54 on 19 Oct 2004

Re: [Templates] hashes and loops
Brandon Hall 23:56 on 21 Oct 2004

Generated at 08:55 on 15 Mar 2005 by mariachi v0.52