I'm creating my own Templating Script by using the ob_get_contents()
as a core method. By using it, it can render out the other files, calling from the one single file.
Just like, lets assume we have 4 files:
- index.php
- header.html
- footer.html
- functions.php
index.php
will call and render the contents of other files (2 html files here). By using the following codes:
//index.php
function render($file) {
if (file_exists($file)) {
ob_start();
include($file);
$content = ob_get_contents();
ob_end_clean();
return $content;
}
}
echo render('header.html');
echo render('footer.html');
But (for example) when header.html
contains a call include('functions.php')
, the included file (functions.php) can't be used again in footer.html
. I mean, i have to make a include again in footer.html
. So here, the line include('functions.php')
have to be containing in both of files.
How to include()
a file without calling it again from child files?