Smarty って面倒よね

 面倒くさがりの考えそうなこと。

 以下のソース使って何が起きても責任は取りませんのであしからず。

<?php

require_once 'smarty.class.php';

/**
 * Smarty 簡易管理クラス
 * 
 * Usage
 * SmartyCS::root('/home/smarty/');
 * SmartyCS::assign('hoge', 'fuga');
 * SmartyCS::display('piyo.html');
 * 
 * @author 金魚屋・J・龍角
 */
class SmartyCS {

	/**
	 * Smarty 関連のルートディレクトリを指定する
	 *
	 * string SmartyCS::root([string root_dir])
	 *
	 * @param string root_dir
	 */
	function root($root_dir = null) {
		static $root;
		if ($root_dir) $root = $root_dir;
		return $root;
	}

	/**
	 * 共有化されたSmarty インスタンスを返す
	 *
	 * Smarty &SmartyCS::getSmarty()
	 *
	 * @return &Smarty
	 */
	function &getSmarty() {
		static $smarty;
		if ($smarty) return $smarty;
		$smarty = new Smarty();
		$smarty->template_dir = SmartyCS::root().'/templates/';
		$smarty->compile_dir  = SmartyCS::root().'/templates_c/';
		$smarty->cache_dir    = SmartyCS::root().'/caches/';
		return $smarty;
	}

	/**
	 * テンプレートに値を割り当てる
	 *
	 * void SmartyCS::assign(string name, mixed var)
	 *
	 * @param string name
	 * @param mixed var
	 */
	function assign($name, $var) {
		$smarty =& getSmarty();
		$smarty->assign($name, $var);
	}

	/**
	 * テンプレートを表示する
	 *
	 * void SmartyCS::display( string template [, string cache_id [, string compile_id]])
	 * 
	 * @param string template
	 * @param string cache_id
	 * @param string compile_id
	 */
	function display($template, $cache_id = null, $compile_id = null) {
		$smarty =& getSmarty();
		$smarty->display($template, $cache_id, $compile_id);
	}
}

?>