Theme class.

A simple templating class.

<?php
class theme {
        public static $cfg = array();
	public static $content;
	public static $html;
	
        function __construct() {
	        theme::$cfg = array('site_path' => '/home/example/', 'site_url' => 'http://example.com', 'theme' => 'default');
        }

	public function load() {
		# Load Theme File
		theme::$html = file_get_contents(theme::$cfg['site_path'] . '/theme/' . theme::$cfg['theme'] . '/base.template.html');
	}
	
	public function output() {
		# Print HTML
		print theme::$html;
	}
	
	public function replace($tag, $data) {
		# Replace Tag
		theme::$html = str_replace($tag, $data, theme::$html);
	}
	
	public function replaceCfg() {
		# Replace Tags
		theme::$html = str_replace('{site_path}', theme::$cfg['site_path'], theme::$html);
		theme::$html = str_replace('{site_url}', theme::$cfg['site_url'], theme::$html);
		theme::$html = str_replace('{theme}', theme::$cfg['theme'], theme::$html);
	}
}
?>

Usage

Load theme with theme::load();

Output html with theme::output();

Replace a tag with theme::replace('tag', 'var');


Comments

Add your comment