- array_push($this->sub_subs[$parent], $tag_name);
- array_push($parents, $parent);
- $parent = $tag_name;
-
- $out .= '~' . $tag_name . '~';
- $in = substr($in, strlen($start_tag));
- $this->sub_templates[$tag_name] = '';
- $this->_load($in, $this->sub_templates[$tag_name], $parents, $parent);
- } else {
- # it's not a start tag or end tag, so let's pass it through:
- $out .= substr($in, 0, 5);
- $in = substr($in, 5);
- }
- } #repeat
- }
-
- # like load() except you pass a string instead of a filename
- function load_str($str) {
- $this->template = '';
- $parents = array('top_level_subs' => array());
- $parent = 'top_level_subs';
- $this->_load($str, $this->template, $parents, $parent);
- }
-
- # This is useful when you have sub-templates that you want to mess with
- # before the main template is run. But can also be used to simply specify
- # the filename ahead of time.
- function load($filename) {
- $this->filename = $filename;
- $this->load_str(read_whole_file($filename));
- }
-
- # Run the template. Pass a filename, or a string, unless you've already
- # specified a template with load()
- function run($templ = false) {
- $template_string = $this->template;
- $template_file = $this->file;
- if($templ !== false) {
- if(strlen($templ) < 150 && file_exists($templ)) {
- $template_file = $templ;
- unset($template_string);
- } else {
- $template_string = $templ;
- }