Add TemplateHelper::render

This commit is contained in:
filp
2013-06-24 23:49:43 +01:00
parent 88143a5734
commit e83780c2ec
2 changed files with 22 additions and 7 deletions
+5 -7
View File
@@ -126,14 +126,12 @@ class PrettyPageHandler extends Handler
// Add extra entries list of data tables:
$v->tables = array_merge($extraTables, $v->tables);
call_user_func(function() use($templateFile, $v, $helper) {
// $e -> cleanup output, optionally preserving URIs as anchors:
$e = array($helper, "escape");
$slug = array($helper, "slug");
require $templateFile;
});
// Temp:
$vars["e"] = array($helper, "escape");
$vars["slug"] = array($helper, "slug");
$vars["v"] = $v;
$helper->render($templateFile, $vars);
return Handler::QUIT;
}
+17
View File
@@ -50,4 +50,21 @@ class TemplateHelper
$slug = preg_replace('/[^\w\d\-\_]/i', '', $slug);
return strtolower($slug);
}
/**
* Given a template path, render it within its own scope.
*
* @param string $__template
* @param array $__variables
*/
public function render($__template, array $__variables = array())
{
// Pass the helper to the template:
$__variables["tpl"] = $this;
call_user_func(function() use($__template, $__variables) {
extract($__variables);
require $__template;
});
}
}