HTML_Template_IT::touchBlock()

HTML_Template_IT::touchBlock() – preserve empty block

Synopsis

require_once 'HTML/Template/IT.php';

boolean HTML_Template_IT::touchBlock ( string $block )

Description

Preserves an empty template block, even if $removeEmptyBlocks is TRUE and no substition of placeholders took place.

Parameter

  • string $block - block to preserve

Return value

boolean - TRUE, if block was found, otherwise IT_Error.

Example

Template - login.tpl.htm

<html>
<body>
<!-- BEGIN login_successfull -->
You have logged in successfully!
<!-- END login_successfull -->
<!-- BEGIN login_failed -->
Login failed
<!-- END login_failed -->
</body>
</html>

Script

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

  
// Remove blocks with no placeholders, or no placeholders set ($removeEmptyBlocks=true)
  
$tpl->loadTemplatefile("login.tpl.htm"truetrue);

  
// hypothetical
  
if (login_successfull($username$password)) {
    
// print login_successfull block. 
    // login_failed is removed, due to $removeEmptyBlocks = true
    
$tpl->touchBlock("login_successfull");
  } else {
    
$tpl->touchBlock("login_failed");
  }

  
$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.