Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Mime::Lite::TT::HTML Input Hash Name?

by doubletb (Initiate)
on Oct 04, 2011 at 14:10 UTC ( #929554=perlquestion: print w/ replies, xml ) Need Help??
doubletb has asked for the wisdom of the Perl Monks concerning the following question:

I have a PERL script that successfully sends PERL messages using MIME::Lite::TT::HTML. However, I'm trying to update the email template to be more dynamic -- I want to include a FOREACH loop that loops through the elements of the hash I pass the template as TmplParams. My problem is that I have no idea what that hash of parameters is called in the template. I understand I can refer to elements of the hash by their keys, but if the keys aren't assigned until runtime, how do I pull them out? Does anyone know? I've tried VARIABLES, TmplParams, a bunch of other random things I've made up... pseudo-code below. I'm looking for what to put in the <???????> to make it work.

SCRIPT: my %emailOptions = { '<random ID>' => { 'queue' = 'Mig', 'priority' = 'high'}, '<random ID 2>' => { 'queue' = 'Inf', 'priority' = 'high'}, '<random ID 3>'=> { 'queue' = 'Mig', 'priority' = 'low'} }; my (%options); $options{INCLUDE_PATH} = '/www/some/where/' my $msg = MIME::Lite::TT::HTML->new( From => someone@somewhere.com , To => someone@elsewhere.com, Subject => 'Neglected Tickets', Template => { ABSOLUTE => 1, html => /path/to/TEMPLATE}, TmplOptions => \%options, TmplParams => \%emailOptions, 'X-MSMail-Priority' => 'High' ); TEMPLATE: <table> <tr> <td><b>ID</b></td> <td><b>Queue</b></td> <td><b>Priority</b></td> </tr> <tr> [% FOREACH ticket IN <??????> %] <td>[% <key> %]</td> <td>[% ticket.queue %]</td> <td>[% ticket.priority %]</td> [% END %] </tr> <table>

Comment on Mime::Lite::TT::HTML Input Hash Name?
Download Code
Re: Mime::Lite::TT::HTML Input Hash Name?
by keszler (Priest) on Oct 04, 2011 at 14:43 UTC

    If I'm understanding you correctly, the %emailOptions that you're passing to MIME::Lite::TT::HTML has essentially random keys, unknown until runtime. What you need is a key name with which to loop over the ticket info from %emailOptions. Can you modify %emailOptions to be:

    my %emailOptions = { tickets => [ { key => '<random ID>', 'queue' = 'Mig', 'priority' = 'high'}, { key => '<random ID 2>', 'queue' = 'Inf', 'priority' = 'high'}, { key => '<random ID 3>', 'queue' = 'Mig', 'priority' = 'low'}, ], };

    Then your template would include:

    [% FOREACH ticket IN tickets %] <td>[% ticket.key %]</td> <td>[% ticket.queue %]</td> <td>[% ticket.priority %]</td> [% END %]

      Thanks for the reply. You understand my problem perfectly, and I'll give your method a shot. It looks like it'll work, although I dislike the redundancy. I'm a little disappointed that the template isn't set up to have an accessible array/hash for those parameters -- like how PERL has @ARGV and @_ arrays for passed-in arguments...

Re: Mime::Lite::TT::HTML Input Hash Name?
by Anonymous Monk on Oct 05, 2011 at 00:20 UTC

    Is this a trick question?

    Template Toolkit, like perl, has a keys function, see Re: Catalyst DBIx Help

    And we program in Perl here, using the executable perl -- there is no PERL

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://929554]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2015-07-04 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (58 votes), past polls