Why use php in your template file? I mean, how does that differ from your index.php code?
Stripping PHP out of your template file can nicely separate your HTML code from your PHP code. Below is a rough outline of a useable token-replacement template class, which parses an html file.
class.template.php
class Template {
public $template;
public function __construct($template) {
$this->template = file_get_contents($template);
}
public function assign($replacement, $new_content) {
$this->template = str_replace("{$replacement}", $new_content, $this->template);
}
public function get_template() {
return $this->template;
}
}
index.php
require_once('class.template.php');
$template = new Template('template.html');
$template->assign('{ReplaceThisText}', 'WithThisText');
echo $template->get_template();
template.html
<html>
<body>
{ReplaceThisText}
</body>
</html>
This is not meant to be used as is, but give you an idea of how to expand this further.