HTML_Template_IT::setRoot()

HTML_Template_IT::setRoot() – テンプレートのルートディレクトリを設定する

Synopsis

require_once 'HTML/Template/IT.php';

void HTML_Template_IT::setRoot ( string $root )

Description

テンプレートディレクトリへのパスを指定します。 HTML_Template_IT::loadTemplatefile() がテンプレートを探す際に、このパスを使用します。 すべてのファイル名の先頭には、指定した文字列が付加されます。

Parameter

  • string $template - テンプレートディレクトリへのパス

Example

ディレクトリツリー


./
./testscript.php
./templates/design01/main.tpl.htm
./templates/design01/table.tpl.htm
./templates/design02/main.tpl.htm
./templates/design02/table.tpl.htm

スクリプト - 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"truetrue);

  
/* ... 変数を代入します .. */

  // 表示します
  
$tpl->show();

?>

Note

This function can not be called statically.