HTML_Template_IT::setTemplate()

HTML_Template_IT::setTemplate() – set a template

Synopsis

require_once 'HTML/Template/IT.php';

boolean HTML_Template_IT::setTemplate ( string $template , boolean $removeUnkownVariables = true , boolean $removeEmptyBlocks = true )

Description

Loads template from a string and controls the behavior in case of unused variables and blocks

Parameter

  • 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

Return value

boolean - Returns TRUE on success, FALSE on failure.

Example

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($templateStringtruetrue);

  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();

?>

Note

This function can not be called statically.

sets an option (Previous) set a variable (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.