[ create a new paste ] login | about

Link: http://codepad.org/NRhPOdmT    [ raw code | fork | 1 comment ]

ninwa - PHP, pasted on Nov 6:
<?php

// A simple templating class
class Template
{
	private $template_string = "";
	private $template_file   = "";
	private $token_key       = Array();
	private $token_value     = Array();
	
	private function loadTemplateFile()
	{
		$this->template_string = file_get_contents( $this->template_file );
	}
	
	function setToken($token, $value)
	{
		$this->token_key[]   = "{" . strtoupper($token) . "}" ;
		$this->token_value[] = $value;
	}
	
	function removeToken($token)
	{
		$index = array_search( "{" . strtoupper($token) . "}" , $this->token_key );
		
		if( $index !== false )
		{
			unset( $this->token_value[$index] );
			unset( $this->token_key[$index]   );
		}
	}
	
	function show()
	{
		$show_string = str_replace($this->token_key, $this->token_value, $this->template_string);
		print($show_string);
	}
	
	function __construct($template_file)
	{
		$this->template_file = $template_file;
		$this->loadTemplateFile();
	}
	
	function __destruct()
	{
	}
}

?>


Output:
No errors or program output.


Create a new paste based on this one


Comments:
posted by ninwa on Nov 6
A simple templating class that I wrote.
reply