Roderick A. Anderson writes:

> Is anyone creating e-mail messages using TT?  I have done the body but
> with the list of recipients changing and getting longer I thought a
> template that constructed the message headers called by a template to
> create the body made more sense.

Just some minor hints:

Since mail headers are picky about newlines and spaces in the wrong
places, I am always using explicit pre-chomp and post-chomp directives
(I always forget what my configuration in Template->new() has been):

----------------------------------------------------------------------
To: [%- FOREACH to = recipients -%]
        [%- '"'; to.name; '"' +%] [%+ '<'; to.email; '>' -%]
        [%- ', ' UNLESS loop.last -%]
    [%- END +%]
----------------------------------------------------------------------

If some headers need more munging, I am doing that munging in the
beginning of the template and then CLEAR the output buffer before
proceeding.  This allows to add empty lines, which can make complex
templates more readable, and is pretty robust against templates which
inadvertedly produce some output unless CALLed.
----------------------------------------------------------------------
[% DEFAULT from    = '[EMAIL PROTECTED]'
           subject = 'ooops!'
%]

[% to_header = BLOCK -%]
    [%- FOREACH to = recipients -%]
        [%- '"'; to.name; '"' +%] [%+ '<'; to.email; '>' -%]
        [%- ', ' UNLESS loop.last -%]
    [%- END +%]
[%- END %]

[%# whatever you need to do, e.g. wrapping long headers,
    can be done here.
%]

[% CLEAR -%]
To: [% to_header +%]
Subject: [% subject +%]
From: [% from +%]

...The body comes here ...
----------------------------------------------------------------------
-- 
Cheers,
haj

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

Reply via email to