Re: [SMARTY] Parsing a string as template

From: Date: Tue, 21 Jun 2005 18:21:39 +0000
Subject: Re: [SMARTY] Parsing a string as template
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-12719@lists.php.net to get a copy of this message
It has and, in my case, I found it *much* easier to cache the string to a temporary template file and parse that. I found a resource for strings and, well, it didn't work well. What I propose sucks, but it was the only easy way I found to do what you're asking for. --Joe On Jun 21, 2005, at 11:17 AM, Maximillian Schwanekamp wrote:
Hello 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! --Maximillian Von Schwanekamp http://www.neptunewebworks.com/ --Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.smarty.general (#12719) next »