HTML_Template_IT::parse()

HTML_Template_IT::parse() – parse a block

Synopsis

require_once 'HTML/Template/IT.php';

void HTML_Template_IT::parse ( string $block = "__global__" , boolean $flag_recursion = false )

Description

Parses the defined block, performs all substitutions and appends the result to already parsed blocks.

Parameter

  • string $block - block to parse. When not set the complete template is used.

  • boolean $flag_recursion - Used internally. Can be ignored

Return value

boolean - Returns TRUE if there was no placeholder to substitute, otherwise FALSE or IT_Error.

Example

The template cvsnames.tpl.htm

<html>
 <table>
<!-- BEGIN row -->
  <tr>
   <td>
    {CVS_USERNAME}
   </td>
   <td>
    {REALNAME}
   </td>
  </tr>
<!-- END row -->
 </table>
</html>

The script

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

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

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

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

  foreach(
$data as $name) {

     
$tpl->setVariable("CVS_USERNAME"$name["cvs_username"]);
     
$tpl->setVariable("REALNAME"$name["realname"]);

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

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

?>

Throws

Possible PEAR_Error values
Error code Error message Reason Solution
IT_BLOCK_NOT_FOUND " Cannot find this block block " The given block does not exists. Check for typing mistakes in the argument.

Note

This function can not be called statically.

load a template file (Previous) parse the current block (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.