barinbritva
6/9/2014 - 12:20 PM

PHP native templater

PHP native templater

function render($template, $data = array()) {
	$template_path = rtrim($_SERVER['DOCUMENT_ROOT'].'/'.$template, '.php').'.php';

	if (!file_exists($template_path)) {
		throw new Exception('Не существует указанного шаблона "'.$template_path.'"');
	}

	extract($data);

	ob_start();
	require($template_path);
	$output = ob_get_contents();
	ob_end_clean();

	return $output;
}