void
HTML_Template_IT::setVariable (
mixed
$placeholder
, mixed
$variable = ""
)
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 its substitution.
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.
Template - cvsnames.tpl.htm
<html> <table> <!-- BEGIN row --> <tr> <td> {CVS_USERNAME} </td> <td> {REALNAME} </td> <td> <ul> <!-- BEGIN project_row --> <li>{PROJECT}</li> <!-- END project_row --> </ul> </td> </tr> <!-- END row --> </table> </html>
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();
?>
This function can not be called statically.