2 // vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4:
3 // +--------------------------------------------------------------------+
4 // | BIFE - Buil It FastEr |
5 // +--------------------------------------------------------------------+
6 // | This file is part of BIFE. |
8 // | BIFE is free software; you can redistribute it and/or modify it |
9 // | under the terms of the GNU General Public License as published by |
10 // | the Free Software Foundation; either version 2 of the License, or |
11 // | (at your option) any later version. |
13 // | BIFE is distributed in the hope that it will be useful, but |
14 // | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 // | General Public License for more details. |
18 // | You should have received a copy of the GNU General Public License |
19 // | along with Hooks; if not, write to the Free Software Foundation, |
20 // | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 // +--------------------------------------------------------------------+
22 // | Created: Wed Jun 17 19:03:14 2003 |
23 // | Authors: Leandro Lucarella <luca@lugmen.org.ar> |
24 // +--------------------------------------------------------------------+
29 // +X2C Class 130 :HIT
31 * Hooks vs. IT (HIT) is a simple template implementation, based on hooks and IT template systems.
35 class HTML_Template_HIT {
37 * Root directory where template files are.
45 * Group of templates to use (a subdirectory in root).
66 * @param string $root Root directory where template files are.
67 * @param string $group Group of templates to use (a subdirectory in root).
72 function HTML_Template_HIT($root = '.', $group = '') // ~X2C
74 $this->__construct($root, $group);
82 * @param int $root Root directory where template files are.
83 * @param int $group Group of templates to use (a subdirectory in root).
88 function __construct($root = '.', $group = '') // ~X2C
91 $this->group = $group;
98 If $vars is an array, the {[keys]} are replaced with [values] ($val is ignored). If is a string, {$vars} is replaced with $val.
100 * @param string $name Name of template to parse.
101 * @param mixed $vars Variables to replace in the template.
102 * @param string $val If $vars is a string, the value to replace for $vars.
107 function parse($name, $vars = '', $val = '') // ~X2C
110 $file = "{$this->root}/{$this->group}/$name.tpl.html";
112 $file = "{$this->root}/$name.tpl.html";
114 if (!isset($this->cache[$file])) {
115 $this->cache[$file] = join('', file($file));
117 //if (!is_readable($file)) {
118 // trigger_error("Can't read '$file'.");
121 if (is_string($vars)) {
122 $vars = array($vars => $val);
124 foreach ($vars as $key => $val) {
125 $keys[] = '{' . $key . '}';
128 return str_replace($keys, $vals, $this->cache[$file]);
130 return $this->cache[$file];