Menu

#19 template.inc Hack: Send output to FILES

closed
None
5
2013-11-16
2002-03-07
No

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
file.

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
file!!
*/
function p_file($varname , $path , $file_name) {
// Open the file
$fp = fopen ($path.$file_name, "w+");
// Send the output
fwrite($fp,$this->finish($this->get_var($varname)));
fclose($fp);
}

Pretty simple, isn't it??

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

Thankx for a great library.

Txarly :)

Discussion

  • Richard Archer

    Richard Archer - 2002-03-07

    Logged In: YES
    user_id=279311

    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.

    ...R.

     
  • Richard Archer

    Richard Archer - 2002-04-25

    Logged In: YES
    user_id=279311

    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
     

Log in to post a comment.