void
HTML_Template_IT::setRoot (
string $root
)
テンプレートディレクトリへのパスを指定します。 HTML_Template_IT::loadTemplatefile() がテンプレートを探す際に、このパスを使用します。 すべてのファイル名の先頭には、指定した文字列が付加されます。
string $template
-
テンプレートディレクトリへのパス
ディレクトリツリー
スクリプト - testscript.php
<?php
/*
* testscipt.php - ランダムなデザインを設定する
*/
require_once "HTML/Template/IT.php";
$tpl = new HTML_Template_IT();
$randomNumber = (int) round(rand(0,1));
switch ($randomNumber)
{
case 0:
// ルートを design01 に指定し、そこから main.tpl.htm を探します
$tpl->setRoot("./templates/design01");
break;
case 1:
default:
// ルートを design02 に指定し、そこから main.tpl.htm を探します
$tpl->setRoot("./templates/design02");
break;
}
/* switch の中の setRoot で指定したディレクトリによって、
* ./templates/design01/main.tpl.htm あるいは
* ./templates/design02/main.tpl.htm のいずれかが
* 読み込まれます */
$tpl->loadTemplatefile("main.tpl.htm", true, true);
/* ... 変数を代入します .. */
// 表示します
$tpl->show();
?>
This function can not be called statically.