#native_company# #native_desc#
#native_cta#

Templates

By Luis Tena
on March 4, 2002

Version: 1.1

Type: Class

Category: HTML

License: GNU General Public License

Description: Try this simple to use template manager to separate the logical part from the html part.

<?php
/*
Template generation class:
Author: Luis Tena O. <[email protected]>
Date: 4 - Marzo - 2002
Licence: GNU

Description:
This class allows you to separate the logic part from the html in a simple way.

Usage (Logic Part):
// Create the object...
$Tmpl = new Template('path/to/my/templates/');

//GET THE QUERY + RESULTS IN ONE VARIABLE
//Now we register the variable
$Tmpl->RegVar('<#NAME#>','Luis Tena');
$Tmpl->RegVar('<#AGE#>','22');

//Finally we print, email, save in a file the template output.
//In this case we print the output
print $Tmpl->SpitContent('template_file.html');
//OR just email the template output
$content = print $Tmpl->SpitContent('template_file.html');
email('[email protected]','subject',$content,$headers);

Usage (HTML Part):
Define one type of template tags like <##> <!!> <%%> [] {} {##} and on
in this example Ill use <##>
<html>
<head>
	<title>Welcome: <#NAME#></title>
</head>
<body>
Hi <#NAME#> you are <#AGE#> years old.
<br><br>
Thanx for visiting <#NAME#>
</body>
</html>

Thats it.
*/

class Template
{
	var $ARRAYVALUES	= array();
	var $path2tmpl;
	
	function Template($path){
		$this->path2tmpl = $path;
	}
	
	function RegVar($key,$val){
		$this->ARRAYVALUES[$key] = $val;
	}
	
	function  SpitContent ($archivo){
		$file = $this->path2tmpl.$archivo;
		if(!@fopen($file,"r")){
			 print 'No se pudo encontrar el file del templete '.$file;
		}else{
			$template = file($file);
			foreach($template AS $line){
				foreach($this->ARRAYVALUES AS $key => $val){
					if(eregi($key,$line)){
						$line = eregi_replace("$key",$val,$line);
						$data = $line;
					}else{
						$data = $line;
					}
				}
			$contenido .= $data;
			}
		}
	return $contenido;
	}
}
?>