OK this is the template class
I renamed get_contents() to contents()
I worked with the code a bit and now the templates are replacing each other ok but instead of showing all of the results from my news query it only shows the last result.
class template {
private $template;
function load($filepath) {
$this->template = file_get_contents($filepath);
$this->template = ereg_replace("<!-- START COMMENTS -->(.*\s*)<!-- END COMMENTS -->", "",
$this->template);
}
function contents() {
return $this->template;
}
function replace($var, $content) {
$this->template = str_ireplace("<#$var#>", $content, $this->template);
}
function publish() {
echo $this->template;
}
}
Here is the code in the while loop
$template = new template;
$template->load("template/news_tpl.html");
$template->replace("member_name", "$member_name");
$template->replace("website", "$member_website");
And this is the final code that calls the main template and echos the output.
$main_template = new template();
$main_template->load("template/main_tpl.html");
$replacement = $template->contents();
$main_template->replace("CONTENT", $replacement);
$main_template->publish();