Yaf_View_Simple::render
(Yaf >=1.0.0)
Render a template
Description
Renders a template and returns the result as a string. The template is included as a plain PHP script, so any PHP code in it is executed, and assigned variables are available under their names.
Unlike Yaf_View_Simple::display, the result is returned instead of being appended to the Yaf_Response_Abstract body.
Parameters
tplThe path to the template, relative to the template directory set by
Yaf_View_Simple::setScriptPathorapplication.view.directory.varsOptional variables to assign for this render; they override assigned variables with the same name.
Return Values
The rendered result as a string, or false on failure.
Examples
Yaf_View_Simple::render example
<?php
class ProductController extends Yaf_Controller_Abstract
{
public function detailAction()
{
/* render the template and post-process the result */
$html = $this->getView()->render("product/detail.phtml", array(
"name" => "Yaf in Action",
"price" => "29.90",
));
$this->getResponse()->setBody($html);
return false; // skip auto-rendering
}
}
?>Template example
<h1><?php echo $name; ?></h1>
<p>Price: <?php echo $price; ?> EUR</p>The above example will output something similar to:
<h1>Yaf in Action</h1>
<p>Price: 29.90 EUR</p>See Also
Yaf_View_Simple::displayYaf_View_Simple::evalYaf_View_Simple::assign