Phalcon PHP framework, as well as the PHP-Sundown C implementation of Markdown.
It is a very simple CMS which previously would just echo out compiled HTML. But I am using the Volt template engine in Phalcon. It renders .volt
files to native PHP. This means that I cannot just spit out raw HTML. I need to create a render function that passes an array of data to my PHP file.
Here is that function:
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', $view_data);
This works! It is a handy little function for passing data into a PHP file.
If you wanted to use an object, you would need to cast it to an array first.
I'm a full-stack developer, co-organizer of PHP Vancouver meetup, and winner of a Canadian Developer 30 under 30 award. I'm a huge Open Source advocate and contributor to a lot of projects in my community. When I am not sitting at a computer, I'm trying to perfect some other skill.