Location: PHPKode > scripts > Simple Object > simpletemplate.php
<?php
	if ( !defined('SO_TEMPLATE_FILE') ) {
		define('SO_TEMPLATE_FILE',1);
		define('SO_TEMPLATE_STRING',2);
	}

	class SimpleTemplate extends SimpleObject {
		
		function SimpleTemplate($item_data=array()) {
			parent::SimpleObject(SO_NOT_STRICT);
			$this->import($item_data);
		}
		
		function fetch($template,$template_mode=SO_TEMPLATE_FILE) {
			switch ( $template_mode ) {
				case SO_TEMPLATE_STRING:
					$src = $template;
					break;
				case SO_TEMPLATE_FILE:
				default:
					$src = file_get_contents($template);
					break;
			}
			$keys = array_keys($this->vars);
			foreach ( $keys as $key ) {
				$src = str_replace('<!--$'.$key.'-->',$this->get($key),$src);
			}
			return $src;
		}
		
		function display($template_file,$template_mode=SO_TEMPLATE_FILE) {
			echo $this->fetch($template_file,$template_mode);
		}
	}
?>
Return current item: Simple Object