I am trying to build my own simple template handler to easily be able to nest and combine files into variables and call these variables when neccessary, as shown below:
$partial['header'] = 'header.php';
foreach($partial as $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 the header.
The question:
Obviously, loading a PHP file by file_get_contents isn’t going to call any PHP code inside the loaded file and I am sure that there’s better options available then using eval. What should I change to be able to use PHP inside my template files?
More ugly is possible but doing exactly what you’re wanting :
Then you can call it :
I copied that from a comment in the PHP manual but can’t find it anymore (and that’s why maybe it’s too ugly :D)