<?
# ATemplate
# 2000-10-5 v1.0, E.Soysal
# http://www.soysal.com/atemplate
#
# Free to use/distribute/modify
#
class atemplate {
##PRIVATE##
var $templates = array();
var $outputs = array();
##PUBLIC##
function atemplate($a) {
while(list($tplname, $filename)=each($a)) {
$this->templates[$tplname]= $this->readtpl($filename);
}
}
function embed($name, $toname) {
$this->outputs[$toname] =
str_replace('{'.$name.'}',
$this->outputs[$name], $this->outputs[$toname]);
$this->outputs[$name] ='';
}
function process($tplname, $a) {
$tmp = $this->templates[$tplname];
while (list($var, $val)=each($a)) {
$tmp =str_replace('{'.$var.'}', $val, $tmp);
}
$this->outputs[$tplname] .= $tmp;
}
function printit() {
while(list( , $val)=each($this->outputs)) {
print("$val\n");
}
}
function append($name, $toname) {
$this->outputs[$toname] .= $this->outputs[$name];
$this->outputs[$name] = '';
}
##PRIVATE##
function readtpl($filename) {
if(file_exists($filename)) {
$res =implode("\n",file($filename));
return $res;
}
die("Can not find $filename");
}
}
?> |