root = $root; $this->group = $group; $this->cache = array(); } function parse($name, $vars = null, $val = null) { if ($this->group) { $file = "{$this->root}/{$this->group}/$name.tpl.html"; } else { $file = "{$this->root}/$name.tpl.html"; } if (!isset($this->cache[$file])) { $this->cache[$file] = join('', file($file)); } //if (!is_readable($file)) { // trigger_error("Can't read '$file'."); //} if ($vars) { if (is_string($vars)) { $vars = array($vars => $val); } foreach ($vars as $key => $val) { $keys[] = '{' . $key . '}'; $vals[] = $val; } return str_replace($keys, $vals, $this->cache[$file]); } else { return $this->cache[$file]; } } } ?>