Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

fTemplating output into a variable?

posted by unknow 8 years ago

How can I place or inject a template file into variable?

$template_output = $template->inject('/path/to/template.php'); 


$template->add('template_output', '/path/to/template.php');
$template_output = $template->place('template_output');

It's there a solution to get the output to a variable except ob_start (); ... ob_end_flush(); ?

Nobody write :) ... , so I guess that the only way would be:

if (!fBuffer::isStarted()) fBuffer::start();

$template_output = fBuffer::stopCapture();

posted by unknow 8 years ago

This is a technique I use fairly often. Particularly for e-mail templates. The easiest way, if you do it commonly is to just create a class that extends fTemplating and have a method which wraps the place call with the buffer and returns it. I don't think I've done this yet on the View class in inKWell, primarily cause I'm looking for a semantic name which doesn't conflict with existing methods.

$view->get() is not an option $view->digest() is used to digest string content into an element

$view->capture() -- maybe?

posted by mattsah 8 years ago

Might I also add, this could probably be solved, at least for my usage, pretty simply if fEmail->setBody and setHTML() could receive an fTemplate (maybe they do already?) and will automatically buffer the output and use it.... perhaps I'll add this to the .inK fork.

posted by mattsah 8 years ago