* $template->setTemplate('This is ');
*
*
* @param string $template the template string
*/
public function setTemplate($template)
{
$this->template = $template;
}
/**
* Set a file as a template. The file can be any regular PHP file.
*
*
* $template->setTemplateFile(dirname(__FILE__) . '/template/foo.php');
*
*
* @param string $filePath The (absolute or relative to the include path) file path
*/
public function setTemplateFile($filePath)
{
$this->templateFile = $filePath;
}
/**
* Render the template using the variable provided as arguments.
*
*
* $template = new PropelTemplate();
* $template->setTemplate('This is ');
* echo $template->render(array('name' => 'Mike'));
* // This is Mike
*
*
* @param array $vars An associative array of argumens to be rendered
*
* @return string The rendered template
*/
public function render($vars = array())
{
if (null === $this->templateFile && null === $this->template) {
throw new InvalidArgumentException('You must set a template or a template file before rendering');
}
extract($vars);
ob_start();
ob_implicit_flush(0);
try
{
if (null !== $this->templateFile) {
require($this->templateFile);
} else {
eval('?>' . $this->template . '