Skip to content

Instantly share code, notes, and snippets.

@atbradley
Created June 5, 2013 15:47
Show Gist options
  • Save atbradley/5714931 to your computer and use it in GitHub Desktop.
Save atbradley/5714931 to your computer and use it in GitHub Desktop.
define('TEMPLATE_DIR', 'path/to/my/templates');
/**
* Processes a PHP template.
*
* Looks in OCRA_TEMPLATE_DIR for {$template}.tpl, and includes it,
* probably generating an HTML page.
*
* @author Adam Bradley <hisself@adambradley.net>
*
* @param string $template The template file to use
* @param array $data Data To be passed to the template.
* @param boolean $return If true, return a string, otherwise print the result to the browser.
*
* @return boolean|string The template results (if $return=true) or the return value of ob_end_flush()
*
* @todo Should throw an exception if the template file doesn't exist.
*/
function do_template($template, Array $data, $return=false) {
//TODO: Should throw an exception if the template doesn't exist.
extract($data);
ob_start();
include(TEMPLATE_DIR ."/$template.tpl");
if ( $return ) return ob_get_flush();
return ob_end_flush();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment