Login   Register  
PHP Classes
elePHPant
Icontem

File: atemplate.inc.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Ergin SOYSAL  >  ATemplate  >  atemplate.inc.php  >  Download  
File: atemplate.inc.php
Role: ???
Content type: text/plain
Description: atemplate class implementation.
Class: ATemplate
Another html template implementation
Author: By
Last change:
Date: 13 years ago
Size: 1,475 bytes
 

Contents

Class file image Download
<?
#   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");
     }
  }
?>