NYCPHP Meetup

NYPHP.org

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

Carlos A Hoyos cahoyos at us.ibm.com
Tue May 6 12:07:08 EDT 2003








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


                                                                                                                                      
                      Chris Snyder                                                                                                    
                      <chris at psydeshow.        To:       NYPHP Talk <talk at nyphp.org>                                                  
                      org>                     cc:                                                                                    
                                               Subject:  Re: [nycphp-talk] Looking for a PHP equivalent to Perl Text::Template         
                      05/05/2003 06:40                                                                                                
                      PM                                                                                                              
                      Please respond to                                                                                               
                      talk                                                                                                            
                                                                                                                                      



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.



--- Unsubscribe at http://nyphp.org/list/ ---







More information about the talk mailing list