|
Posted by Monte Ohrt on 09/30/56 11:19
About the easiest way I've handled this is two templates:
email_subject.tpl
email_body.tpl
then
$subject = $smarty->fetch('email_subject.tpl');
$body = $smarty->fetch('email_body.tpl');
Yes, this requires one extra template, but it keeps the content
controlled from templates and avoids all the extra
capture/caching/resource hoopla that would be needed otherwise. Using
separate templates also clearly defines the separation of subject/body,
and is obvious to the template designer what each is for.
Monte
Maximillian Schwanekamp wrote:
>zHello all,
>
>The application I'm working on occasionally produces email (e.g. new
>user welcome, password reminder, etc). I use Smarty templates for the
>body of the message. I'm wondering if it's possible to use a smarty
>instance to parse a given string (the email subject line) as a template,
>without a pre-existing template file and without going to the lengths
>required for setting an alternate template resource. Right now, I have
>the subject line in a capture block within the template itself, and then
>define I have a public get method to return the $smarty->_tpl_vars array
>value from the capture. Is there a better way?
>
>For clarification, here's a snippet from how I do it presently:
>message.tpl excerpt:
>{strip}
>{capture assign="subject"}
>Here is your {$site_name} login info, {$first_name}
>{/capture}
>{/strip}
>Dear {$first_name}...etc etc
>
>login.php excerpt:
>/* Template class extends Smarty to autoset template dirs, and has
>method to get the _tpl_vars value */
>$smarty =& new Template;
>$mailer =& new Mailer;
>$smarty->assign('site_name','Example Site');
>$smarty->assign('first_name','Max');
>$mailer->Body = $smarty->fetch('message.tpl');
>$mailer->Subject = $smarty->get_template_var('subject'); // call to the
>custom method
>$sent = $mailer->Send();
>
>I'm feeling like this has got to be a road that has been travelled
>before. Manuel Lemos' MimeMessage class (mentioned in the Smarty wiki)
>has an example for using Smarty templates for the message body, but not
>the subject line, AFAIK. Any suggestions would be appreciated. Thanks
>in advance!
>
>
>
[Back to original message]
|