Skip to content

Instantly share code, notes, and snippets.

@tored
Forked from james2doyle/render-php-file.php
Last active August 29, 2015 14:22
Show Gist options
  • Save tored/8d11bda495723f3609f2 to your computer and use it in GitHub Desktop.
Save tored/8d11bda495723f3609f2 to your computer and use it in GitHub Desktop.
Render a PHP file as a template
function renderPhpFile($filename, $vars = null) {
if (is_array($vars) && !empty($vars)) {
extract($vars);
}
ob_start();
include $filename;
return ob_get_clean();
}
// usage
echo renderPhpFile('views/templates/index.php', $data_for_view);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment