#19 template.inc Hack: Send output to FILES


Hi to all!

I've been working in a project in which I needed to
send HTML emails. I love the PHPLib's template Class,
but It didn't have any method to output the whole
bunch of HTML to a file instead to the browser. I
needed this because the HTML of the email was dynamic,
you know: It needed brackets in it. {user_name}, etc.
I generated an HTMl file, and then attached to the
email using a fantastic class that I found out there.

I've added a new method, called p_file(), that is
quite similar to p(), but instead of printing all the
output of the page, it stores the whole bunch in a

So... here is it:

/* public: p(string $varname)
* varname: name of variable to print.
function p($varname) {
print $this->finish($this->get_var($varname));

/* public: p_file(string $varname, string $path,
string $file_name)
* varname: name of variable to print.
* Txarly :) Hack!! Print the complete output to a
function p_file($varname , $path , $file_name) {
// Open the file
$fp = fopen ($path.$file_name, "w+");
// Send the output

Pretty simple, isn't it??

Hope this'd help. Maybe it could be added in the next

Thankx for a great library.

Txarly :)


  • Richard Archer

    Richard Archer - 2002-03-07

    Logged In: YES

    I suggest using the already-present t->get() function?

    Get the finished template output and write it to a file in
    your code. Or inject it straight into your mail queue.


  • Richard Archer

    Richard Archer - 2002-04-25

    Logged In: YES

    Closing this because the feature should be part of the
    application logic, not the template engine.

  • Richard Archer

    Richard Archer - 2002-04-25
    • assigned_to: nobody --> richardarcher
    • status: open --> closed

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks