HTML_Template_IT::setTemplate() -- set a template
Описание
Loads template from a string and controls the behavior in case of unused
variables and blocks
Параметр
string $template -
The content of the template.
boolean $removeUnknowVariables -
if TRUE, not substituted placeholders in a block will
be removed
boolean $removeEmptyBlocks -
if TRUE, not touched blocks will be removed
Возвращаемое значение
boolean -
Возвращает TRUE в случае успеха и FALSE при неудаче.
Пример
Пример 43-1. Script
<?php
require_once "HTML/Template/IT.php";
$data = array
(
"0" => array("Stig", "Bakken"),
"1" => array("Martin", "Jansen"),
"2" => array("Alexander", "Merz")
);
$templateString = <<<EOD
<html>
<table>
<!-- BEGIN row -->
<tr>
<!-- BEGIN cell -->
<td>
{DATA}
</td>
<!-- END cell -->
</tr>
<!-- END row -->
</table>
</html>
EOD;
$tpl = new HTML_Template_IT();
$tpl->setTemplate($templateString, true, true);
foreach($data as $name) {
foreach($name as $cell) {
// Assign data to the inner block
$tpl->setCurrentBlock("cell") ;
$tpl->setVariable("DATA", $cell) ;
$tpl->parseCurrentBlock("cell") ;
}
// parse outter block
$tpl->parse("row");
}
// show
$tpl->show();
?> |
|
Заметка
Эта функция не должна вызываться статически.