Last active
April 4, 2024 15:33
-
-
Save james2doyle/6378289 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 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
<?php | |
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); |
Clean ! Thank you !
Nice, thanks mate!
awesome! thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow! Thank you!