[nycphp-talk] Looking for a PHP equivalent to Perl Text::Template
Chris Snyder
chris at psydeshow.org
Mon May 5 18:40:38 EDT 2003
Emmanuel. M. Decarie wrote:
>Hello,
>
>I'm looking to a PHP equivalent to the Perl module Text::Template.
>
>I was perusing the Smarty documentation, but, maybe I missed
>something, but it doesn't look that I can use it the in same way.
>
>What I want to do is to assign the result of parsing the template to
>a variable. This is very convenient for example when you need to send
>email.
>
>---------------------------------------------
>Perl example:
>---------------------------------------------
>
>Dear {$title} {$lastname},
>It has come to our attention that you are delinquent in your
> {$monthname[$last_paid_month]} payment. Please remit
> ${sprintf("%.2f", $amount)} immediately, or your patellae may
> be needlessly endangered.
>Love,
>Mark "Vizopteryx" Dominus
>
>
>
You could do essentially this by bringing the template into your
controlling script and eval()'ing it -- something like:
$template= file_get_contents("/path/to/template.html");
$command= "\\$output= \\"$template\\";";
eval($command);
print $output;
You couldn't pull off the sprintf() call in the middle of that, but
everything else will work. You don't even need the curly brackets.
chris.
More information about the talk
mailing list