-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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