(Yaf >=2.2.0)
Yaf_View_Simple::eval — Render a template string
Renders a template given as a string and returns the result.
Nota:
Since no template file is involved, the template directory is not consulted.
tpl_contentThe template content as a string.
varsOptional variables to assign for this render; they override assigned variables with the same name.
The rendered result as a string, or false on failure.
Example #1 Yaf_View_Simple::eval() example
<?php
class IndexController extends Yaf_Controller_Abstract
{
public function indexAction()
{
$template = "<h1><?php echo htmlspecialchars($title); ?></h1>";
/* render the template string without touching the filesystem */
$html = $this->getView()->eval($template, array("title" => "Breaking News"));
$this->getResponse()->setBody($html);
return false; // skip auto-rendering
}
}
?>Il precedente esempio visualizzerà qualcosa simile a:
<h1>Breaking News</h1>