I would like to ask some help and ideas on how to implement a loop inside the template. I can do foearch below but how can i include it to the template and show it in the re
Just don't re-invent the wheel, PHP works wonderfully as a templating language:
The template class
class Template
{
private $template;
private $vars;
function load($filepath) {
$this->template = $filepath;
}
function replace($var, $content)
{
$this->vars[$var] = $content;
}
function publish()
{
extract($this->vars);
include($this->template);
}
}
?>
The template design.phtml
Hello
The time is:
Embedded PHP works too!"; ?>
The use is pretty much the same, just assign more than one row to make use of it:
include "template.class.php";
$template = new Template;
$template->load("design.phtml");
$template->replace("title", "My Template Class");
$rows = array();
$rows[] = array(
"name" => "William",
"datetime" => date("m/d/y"),
);
$template->replace("rows", $rows);
$template->publish();
?>
Hope this is helpful.