What is the best way to create templates using php?

advertisements

I have a class that gathers templates and displays the final output after connecting all the templates.

class Template{

$private $output = '';

public function Load_Template($template, $data = null){
    ob_start();
    include($template);
    $this->output .= ob_get_clean();
}

public function Display($add_footer = true){
    echo $this->output;
}

}

Now, Currently my templates look something like this.

<h1><?php echo $data['name']; ?></h1>

or the more complex ones that involve loops look more like

<ul>
  <li>
  <?php foreach($data as $user){ ?>
   <h1><?php echo $user['name']; ?></h1>
  <?php } ?>
  </li>
</ul>

Actually theres way more data than that in them, but im sure you guys get the point. Now, I have heard people say thats it better to have templates like this

<h1>{name}</h1>

or

<ul>
  <li>
   <h1>{name}</h1>
  </li>
</ul>

and then use a str_replace function... Now, if im using a foreach loop, how would I accomplish something like this... should i alter my class, and if so can i get some ideas as to how... And do you guys suggest using templates with


Smarty is too redundant! Your class with the function of cutting a page is enough.