PHPのテンプレートエンジンといえば、Smartyです。
Smartyを使うときの作法として、自分では次のように継承クラスを必ず用意するようにしています。
xxxxSmarty.class.php(xxxは作成するSystem名)
<?php
require_once("Smarty.class.php"); // smarty.class.phpの指定。環境によって異なります。
class xxxxSmarty extends Smarty{ // Smartyクラスを継承したxxxxSmaryクラスを定義します。
public function __construct(){ // __construct()はPH5以上です。
$this->Smarty();
$this->left_delimiter = "{!"; // xoopsと同じにする。(xoopsに慣れてるので)
$this->right_delimiter = "}";
$this->template_dir = "xxxxxxxx/templates";
$this->compile_dir = "xxxxxxxx/templates_c";
}
}
?>
テンプレート定義などソース毎に定義するのは面倒ですから、これで使うときは、
require_once("xxxxSmarty.class.php");
と自作クラスだけ呼ぶようにします。
$hoge = new xxxxSmarty();
__constructにより、newされたときに自動で実行されますので、再定義の必要がありません。
