logo       

Re: hashes and loops: msg#00085

Subject: Re: hashes and loops
Whenever I have passed an array like yours, I have found it best to push an 
anonymous hash like this

push @emails, { from => "fred", to => "wilma", subj => $subj , date => 
"today"};

and then pass the array to the template with a slash.

my $vars = {
         message  => "Hello World\n",
         emaillist => \@emails
};

Your template looks fine,
Sean

On Tuesday 19 October 2004 12:03 pm, Brandon Hall wrote:
> Hello list,
>
> 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.
>
> Here is how things look. The problem must be in my 'push' line below
> or in how i pass it to TT2.
>
>     $sth = $dbh->prepare("SELECT distinct filename from email where
> company_id = 3");
>     $sth->execute();
>     while ( @ref = $sth->fetchrow_array ) {
>         #print "$ref[0]\n";
>         $subj = &get_email_subj($ref[0]);
>         $subj = "<a
> href=\"crm.pl?action=show_email&file=$ref[0]\">$subj</a>"; push @emails, [{
> from => "fred", to => "wilma", subj => $subj , date => "today"}];
>     }
>
>
>     my $file = 'show_company.tpl';
>     my $vars = {
>         message  => "Hello World\n",
>         emaillist => @emails
>     };
>
>
> template:
>  [% FOREACH email IN emaillist %]
>   <tr >
>     <td >[% email.from %]</td>
>     <td >[% email.to %]</td>
>     <td >[% email.subj %]</td>
>     <td >[% email.date %]</td>
>   </tr>
>  [% END %]
>
> tia.
>
> _______________________________________________
> templates mailing list
> templates-MnLy+PD7ppGDO3lXZvfOKmD2FQJk+8+b@xxxxxxxxxxxxxxxx
> http://lists.template-toolkit.org/mailman/listinfo/templates

-- 
Sean Kellogg
2nd Year - University of Washington School of Law
GPSS Senator - Student Bar Association
Editor-at-Large - National ACS Blog [http://www.acsblog.org]
c: 206.498.8207    e: skellogg@xxxxxxxxxxxxxxxx

"Use what talents you possess: the woods would be very silent if no birds
sang there except those that sang best."
              -- Henry Van Dyke


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe