need your help with PHP templating. I\'m new to PHP (I\'m coming from Perl+Embperl). Anyway, my problem is simple:
I use the following helper functions when I work on simple websites:
function function_get_output($fn)
{
$args = func_get_args();unset($args[0]);
ob_start();
call_user_func_array($fn, $args);
$output = ob_get_contents();
ob_end_clean();
return $output;
}
function display($template, $params = array())
{
extract($params);
include $template;
}
function render($template, $params = array())
{
return function_get_output('display', $template, $params);
}
display will output the template to the screen directly. render will return it as a string. It makes use of ob_get_contents to return the printed output of a function.