HTML_Template_IT::loadTemplatefile()

HTML_Template_IT::loadTemplatefile() – load a template file

Synopsis

require_once 'HTML/Template/IT.php';

boolean HTML_Template_IT::loadTemplatefile ( string $filename , boolean $removeUnknownVariables = true , boolean $removeEmptyBlocks = true )

Description

Loads a template from a file and generates internal lists for blocks and variables.

Parameter

  • string $filename - file to load

  • boolean $removeUnknownVariables - if TRUE, not substituted placeholders in a block will be removed

  • boolean $removeEmptyBlocks - if TRUE, not touched blocks will be removed. Blocks can be touched with HTML_Template_IT::touchBlock().

Return value

boolean - Returns TRUE on success, FALSE on failure.

Example

Templatefile main.tpl.htm

<html>
 <body>
User {USERNAME} logged in successfull as {ROLE}.
 </body>
</html>

Script with $removeUnknownVariables = FALSE

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

$tpl = new HTML_Template_IT('.');
$tpl->loadTemplatefile ('main.tpl.htm'falsefalse);

$tpl->setVariable ('USERNAME''foo');
// Placeholder ROLE is not set
$tpl->show();
?>

Output


User foo logged in successfull as {ROLE}.

Script with $removeUnknownVariables = TRUE

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

$tpl = new HTML_Template_IT('.');
$tpl->loadTemplatefile ('main.tpl.htm'truetrue);

$tpl->setVariable ('USERNAME''foo');
// Placeholder ROLE is not set, but $removeUnknownVariables is set to true.
$tpl->show();
?>

Output


User foo logged in successfull as .

Note

This function can not be called statically.

returns an array of all global variables from the variable cache (Previous) parse a 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:

Note by: pierre2543@hotmail.com
It is possible to do file includes when calling loadTemplatefile.

File sample.tlp:
<html>
<body>
<!-- INCLUDE include.inc -->
</body>
</html>

File include.inc:
<h1>foo</h1>

Calling:
$it->loadTemplatefile('sample.tpl');

Result:
<html>
<body>
<h1>foo</h1>
</body>
</html>

------------------------
Louis-Pierre Charbonneau