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

View this page in Last updated: Sun, 01 Jul 2007
English | Dutch | French | German | Hungarian | Japanese | Polish | Russian | Spanish | Plain HTML

HTML_Template_IT::setVariable()

HTML_Template_IT::setVariable() -- set a variable

Leírás

Set the value of a variable in the current template block. If $placeholder is an array the key of an element is treated as a placeholder name while the value is treated as it's substitution.

Paraméterek

  • mixed $placeholder - name of the placeholder to substitute or a array with the placeholder as key and the data to assign as value.

  • mixed $variable - if $placeholder is not a array, the value to assign to the placeholder.

Példa

Példa 43-2. Script


<?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", true, true);

  foreach($data as $name) {
     // Assign data to the inner block
     
     $tpl->setCurrentBlock("project_row");
     foreach ($name['projects'] as $projectname) {
         $tpl->setVariable("PROJECT", $projectname);
         $tpl->parseCurrentBlock();
     }
     
     // use the possbility to set the placeholders using an assoc array
     $tpl->setVariable(
                      array("CVS_USERNAME" => $name["cvs_username"],
                            "REALNAME" => $name["realname"])
                      );

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

  // show() parses the __global__ block and
  // print the output
  $tpl->show();

?>

Megjegyzés

Ez a függvény nem hívható statikusan.

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

Download Documentation Last updated: Sun, 01 Jul 2007
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.