public function testRenderFile() { $t = new PropelTemplate(); $t->setTemplateFile(dirname(__FILE__) . '/template.php'); $res = $t->render(array('name' => 'John')); $this->assertEquals('Hello, John', $res); }
/** * Use Propel's simple templating system to render a PHP file * using variables passed as arguments. * * @param string $filename The template file name, relative to the behavior's dirname * @param array $vars An associative array of argumens to be rendered * @param string $templateDir The name of the template subdirectory * * @return string The rendered template */ public function renderTemplate($filename, $vars = array(), $templateDir = '/templates/') { $filePath = $this->getDirname() . $templateDir . $filename; if (!file_exists($filePath)) { // try with '.php' at the end $filePath = $filePath . '.php'; if (!file_exists($filePath)) { throw new InvalidArgumentException(sprintf('Template "%s" not found in "%s" directory', $filename, $this->getDirname() . $templateDir)); } } $template = new PropelTemplate(); $template->setTemplateFile($filePath); $vars = array_merge($vars, array('behavior' => $this)); return $template->render($vars); }