NYCPHP Meetup

NYPHP.org

[nycphp-talk] Looking for a PHP equivalent to Perl Text::Template

Chris Snyder chris at psydeshow.org
Tue May 6 12:14:44 EDT 2003


Wouldn't you still need to eval() the template in order to substitute 
runtime values for the placeholders?
Output buffering would clean up the code I suggested, but I'm not sure 
how it would solve the problem of separating logic and design...


Carlos A Hoyos wrote:

>You can use the output buffer functions. Easier than eval, and you can use
>all of the php functions to build the output.
>Look at ob_start() and ob_get_contents()....
>
>this are one of the overlooked treassures in php ; )
>
>Carlos
>
>
>                                                                                                                                             
>
>>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.
>
>
>
>
>
>
>
>
>
>
>--- Unsubscribe at http://nyphp.org/list/ ---
>
>
>
>  
>


-- 
do you have a photoblog yet?
http://fotola.com  (help beta-test!)





More information about the talk mailing list