model view controller - PHP: Including files for template -
i trying build own simple template handler able nest , combine files variables , call these variables when neccessary, shown below:
$partial['header'] = 'header.php'; foreach($partial $part => $view ) { $output[$name] = file_get_contents( apppath .'views/' . $view . '.php' ); } extract($output, extr_prefix_all, 'template' ); include 'mytemplate.php';
the mytemplate.php
template file:
<?php echo $template_header; // shows header.
the question:
obviously, loading php file file_get_contents
isn't going call php code inside loaded file , sure there's better options available using eval
. what should change able use php inside template files?
more ugly possible doing you're wanting :
function custom_get_content($filename){ if (is_file($filename)) { ob_start(); include $filename; $contents = ob_get_contents(); ob_end_clean(); return $contents; } }
then can call :
foreach($partial $part => $view ) { $output[$name] = custom_get_content( apppath .'views/' . $view . '.php' ); }
i copied comment in php manual can't find anymore (and that's why maybe it's ugly :d)
Comments
Post a Comment