3 ms·
Here is one of my PHP standards... I prefer this to more complex template systems, although the idea is borrowed from Symfony I think. The style I try to adhere
by owyn 15y ago
Here is one of my PHP standards... I prefer this to more complex template systems, although the idea is borrowed from Symfony I think. The style I try to adhere to is to only use simple variables and loops in html templates. This is the basic idea:
function render($data, $templateFile) {
extract( $data );
ob_start();
require $templateFile;
echo ob_get_clean();
}
It turns an array (or DTO object using get_object_vars) into global variables in the template, so this code in a controller
$data->foo = "bar";
Is accessed in the template like this:
<?= $foo ?>