HTML_Template_IT::setTemplate() (Previous) (Next) HTML_Template_IT::show()

View this page in Last updated: Sun, 05 Oct 2008
English | Dutch | French | German | Hungarian | Japanese | Polish | Russian | Spanish | Plain HTML

HTML_Template_IT::setVariable()

HTML_Template_IT::setVariable() -- 変数を代入する

説明

カレントブロック内の変数に値を代入します。 $placeholder が配列の場合は、 要素のキーがプレースホルダ名として扱われ、その要素の値で置換されます。

パラメータ

  • mixed $placeholder - 置換されるプレースホルダ、 またはプレースホルダをキー、代入する内容を値とした配列

  • mixed $variable - $placeholder が配列以外の場合、指定された値がプレースホルダに代入されます。

例 47-2スクリプト


<?php
  require_once "HTML/Template/IT.php";

  $data = array
  (
    "0" => array("cvs_username" => "pajoye", 
                 "realname" => "Pierre-Alain Joye",
                 "projects" => array("PEAR", 
                                     "PEAR_Frontend_Web", 
                                     "PEAR_RemoteInstaller", 
                                      "HTML_Template_IT")),
    "1" => array("cvs_username" => "dsp",
                 "realname" => "David Soria Parra",
                 "projects" => array("HTML_Template_IT"))
  );

  $tpl = new HTML_Template_IT("./templates");

  $tpl->loadTemplatefile("cvsnames.tpl.htm"truetrue);

  foreach($data as $name) {
     // データを内側のブロックに代入します。
     
     $tpl->setCurrentBlock("project_row");
     foreach ($name['projects'] as $projectname) {
         $tpl->setVariable("PROJECT"$projectname);
         $tpl->parseCurrentBlock();
     }
     
     // 連想配列を使用してプレースホルダを設定することも可能です。
     $tpl->setVariable(
                      array("CVS_USERNAME" => $name["cvs_username"],
                            "REALNAME" => $name["realname"])
                      );

     $tpl->parse("row");
  }

  // show() は __global__ ブロックをパースし、
  // 結果を表示します。
  $tpl->show();

?>

注意

この関数は、スタティックにコールする ことはできません。

HTML_Template_IT::setTemplate() (Previous) (Next) HTML_Template_IT::show()

Download Documentation Last updated: Sun, 05 Oct 2008
Do you think that something on this page is wrong? Please file a bug report or add a note.
User Notes:
There are no user contributed notes for this page.