Skip to content

Instantly share code, notes, and snippets.

@eldinphp
Forked from james2doyle/render-php-file.php
Created December 21, 2018 08:41
Show Gist options
  • Save eldinphp/5b6715d7eec45093d7cddc0ec90531d4 to your computer and use it in GitHub Desktop.
Save eldinphp/5b6715d7eec45093d7cddc0ec90531d4 to your computer and use it in GitHub Desktop.
A function to render a php file with data. Allows templating and then sending an array of data into the view.
function render($filename, $vars = null) {
ob_start();
if (!empty($vars)) {
extract($vars);
}
include $filename;
return ob_get_clean();
}
// usage
echo render('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