LSS/Tpl.php
public function output($file,$tags=array(),$echo=true){
		//if there is anything in the buffer, move it to debug
		if(($content = ob_get_contents()) !== '')
			$this->addDebug('<pre>'.$content.'</pre>');
		//init template handler
		$stub_overrides = $this->stub; //backup before initTheme or requested stubs get stomped
		$this->initTheme();
		//start up template engine
		$tpl = new PHPTAL($this->getTplFile($file));
		//init the tpl (load overrides)
		$this->initTpl($tpl,$file);
		//merge stub defaults with the overrides from earlier
		$tpl->stub = $this->stub;
		//setup env for template engine
		$this->setupEnv($tpl);
		//add tags to context
		if(is_array($tags)){
			foreach($tags as $name => $val){
				//dont add invalid vars
				if(strpos($name,'_') === 0) continue;
				if(strpos($name,' ') !== false) continue;
				$tpl->$name = $val;
			}
		}
		//execute template call
		try {
			$out = $tpl->execute();
		} catch(Exception $e){
			//before we throw this upstream we want to restore
			//	the buffer and get more verbose output
			ob_clean();
			echo $content;
			throw $e;
		}
		//if we dont have the tidy extension lets just output now
		if(!extension_loaded('tidy')){
			//print output to browser / terminal
			if($echo){
				$this->reset();
				ob_end_clean();
				echo $out;
				return true;
			} else {
				$this->add($out);
				return $out;
			}
		//we do have tidy so lets do some cleanup
		} else {
			//cleanup the output
			$tidy = new tidy();
			$tidy->parseString($out,Config::get('theme','tidy'),'utf8');
			$tidy->cleanRepair();
			if($echo){
				ob_end_clean();
				echo $tidy;
				return true;
			} else {
				$this->add($tidy);
				return $tidy;
			}
		}
	}
public function output($file,$tags=array(),$echo=true){
		//if there is anything in the buffer, move it to debug
		if(($content = ob_get_contents()) !== '')
			$this->addDebug('<pre>'.$content.'</pre>');
		//init template handler
		$stub_overrides = $this->stub; //backup before initTheme or requested stubs get stomped
		$this->initTheme();
		//start up template engine
		$tpl = new PHPTAL($this->getTplFile($file));
		//init the tpl (load overrides)
		$this->initTpl($tpl,$file);
		//merge stub defaults with the overrides from earlier
		$tpl->stub = $this->stub;
		//setup env for template engine
		$this->setupEnv($tpl);
		//add tags to context
		if(is_array($tags)){
			foreach($tags as $name => $val){
				//dont add invalid vars
				if(strpos($name,'_') === 0) continue;
				if(strpos($name,' ') !== false) continue;
				$tpl->$name = $val;
			}
		}
		//execute template call
		try {
			$out = $tpl->execute();
		} catch(Exception $e){
			//before we throw this upstream we want to restore
			//	the buffer and get more verbose output
			ob_clean();
			echo $content;
			throw $e;
		}
		//if we dont have the tidy extension lets just output now
		if(!extension_loaded('tidy')){
			//print output to browser / terminal
			if($echo){
				$this->reset();
				ob_end_clean();
				echo $out;
				return true;
			} else {
				$this->add($out);
				return $out;
			}
		//we do have tidy so lets do some cleanup
		} else {
			//cleanup the output
			$tidy = new tidy();
			$tidy->parseString($out,Config::get('theme','tidy'),'utf8');
			$tidy->cleanRepair();
			if($echo){
				ob_end_clean();
				echo $tidy;
				return true;
			} else {
				$this->add($tidy);
				return $tidy;
			}
		}
	}
--------------------------------------------------------