Re: [SMARTY] my second plugin! :)

From: Date: Wed, 05 Jun 2002 01:44:07 +0000
Subject: Re: [SMARTY] my second plugin! :)
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-4592@lists.php.net to get a copy of this message
Smarty isn't meant to replace PHP. You could spend a long time parcelling all of PHP's functions into Smarty functions, so that your templates are uber-potent, but Smarty is designed to make it easy for non-techies to produce designs that work in a dynamic environment. If you put SQL in your template and somebody else edits it, bang your application dies. If nobody else is going to be editing the files then what's the point of writing plugins, why not just embed PHP to create a component template (as outlined in the manual)? Regarding digging through big files, your PHP should be much easier to break up into modules than the HTML. The HTML markup is always going to be really complicated for any working site, whereas you can chunk the PHP up and make the SQL easier to find and edit. I think that your blurring of the line between logic and presentation shows that you might not need Smarty in your application. Why not just just use plain vanilla PHP? Ben On Wednesday, June 5, 2002, at 02:27 AM, Travis Low wrote:
That's what I do. Based on values submitted by the user, I assign values in the template. Then I get the template as a string and call the php mail() function to send the mail. I did the same thing when I was using Java-based FreeMarker templates. Travis Monte Ohrt wrote:
Again, mixing your business logic into the template... not a good practice. Let the application handle sending E-mail. But do use a template to format it! Monte Rasmus Schultz wrote:
Here's my second plugin, tested and (apparently) working fine :) - as with my first plugin, however, I'd like your feedback and a chance to clear up any errors before it's posted on the contribs page. It's a block function plugin, that you can use to generate and send email directly from a template - useful for sending out emails on demand (for example a lost password) ... Here's an example: {sendmail subject="This is a test mail" to_name="Rasmus Schultz" to_email="mindplay@mindplay.dk" from_name="Rasmus Twin" from_email="eviltwin@mindplay.dk"} Dear Sir, Just an email to let you know, your new sendmail plugin works. Have a nice day. {/sendmail} This example is quite simple, but a lot of other optional parameters are available, for example you can send HTML mail, change priority, or set a reply-to address. In combination with the MySQL plugin and {if} sections, I think this little plugin could be quite useful? :) Now here's the source: <?php /* * Smarty plugin * -------------------------------------------------------------
* File:     block.sendmail.php
* Type:     block
* Name:     sendmail
* Version: 0.1
* Date:     June 5th, 2002
* Purpose: Send an email using the mail() function,
*           everything within the block will be sent as email.
* Input:    from_name     = Sender's name
*           from_email    = Sender's email address
*           to_name       = Recipient's name
*           to_email      = Recipient's email address
*           replyto_name  = Reply-to name (optional, defaults
                            to same asfrom_name)
*           replyto_email = Reply-to email address (optional,
                            defaults to same as from_email)
*           priority      = Optional, defaults to 3 (Normal)
*           subject       = Subject of email message
*           format        = Either "html" or "plain",
                            optional, defaults to "plain"
* Author: Rasmus Schultz <mindplay(at)mindplay.dk> * ------------------------------------------------------------- */ function smarty_block_sendmail($params, $content, &$smarty) { if ($content) { extract($params); if (empty($format)) { $format = "plain"; } if (empty($to_name)) { $smarty->trigger_error("sendmail: missing 'to_name' parameter"); return; } if (empty($to_email)) { $smarty->trigger_error("sendmail: missing 'to_email' parameter"); return; } if (empty($from_name)) { $smarty->trigger_error("sendmail: missing 'from_name' parameter"); return; } if (empty($from_email)) { $smarty->trigger_error("sendmail: missing 'from_email' parameter"); return; } if (empty($subject)) { $smarty->trigger_error("sendmail: missing 'subject' parameter"); return; } if (empty($replyto_name)) { $replyto_name = $from_name; } if (empty($replyto_email)) { $replyto_email = $from_email; } if (empty($priority)) { $priority = "3"; } $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/".$format."; charset=iso-8859-1\r\n"; $headers .= "From: ".$from_name."<".$from_email.">\r\n"; $headers .= "To: ".$to_name."<".$to_email.">\r\n"; $headers .= "Reply-To: ".$replyto_name."<".$replyto_email.">\r\n"; $headers .= "X-Priority: ".$priority."\r\n"; $headers .= "X-Mailer: smarty.sendmail.php"; mail($to_email, $subject, $content, $headers); } }
-- Travis Low <mailto:travis@dawnstar.org> <http://dawnstar.org/travis> -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


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