| Links: Child Classes Variables Inherited Variables Inherited Methods Methods Variable Detail Method Detail |
Located in File: Program_Root/MiniTemplator.class.php
Requires PHP 4.0.4 or newer.
Template syntax:
Variables:
${VariableName}
Blocks:
<!-- $BeginBlock BlockName -->
... block content ...
<!-- $EndBlock BlockName -->
Include a subtemplate:
<!-- $Include RelativeFileName -->
General remarks: - Variable names and block names are case-insensitive. - The same variable may be used multiple times within a template. - Blocks can be nested. - Multiple blocks with the same name may occur within a template.
Public methods: readTemplateFromFile - Reads the template from a file. setTemplateString - Assigns a new template string. setVariable - Sets a template variable. setVariableEsc - Sets a template variable to an escaped string value. variableExists - Checks whether a template variable exists. addBlock - Adds an instance of a template block. blockExists - Checks whether a block exists. reset - Clears all variables and blocks. generateOutput - Generates the HTML page and writes it to the PHP output stream. generateOutputToFile - Generates the HTML page and writes it to a file. generateOutputToString - Generates the HTML page and writes it to a string.
Home page: http://www.source-code.biz/MiniTemplator
License: This module is released under the GNU/LGPL license (http://www.gnu.org/licenses/lgpl.html).
Copyright 2003: Christian d'Heureuse, Inventec Informatik AG, Switzerland. All rights reserved.
This product is provided "as is" without warranty of any kind.
Version history:
2001-10-24 Christian d'Heureuse (chdh): VBasic version created.
2002-01-26 Markus Angst: ported to PHP4.
2003-04-07 chdh: changes to adjust to Java version.
2003-07-08 chdh: Method variableExists added. Method setVariable changed to trigger an error when the variable does not exist.
2004-04-07 chdh: Parameter isOptional added to method setVariable. Licensing changed from GPL to LGPL.
2004-04-18 chdh: Method blockExists added.
2004-10-28 chdh:
Method setVariableEsc added.
Multiple blocks with the same name may now occur within a template.
No error ("unknown command") is generated any more, if a HTML comment starts with "${".
2004-11-06 chdh:
"$Include" command implemented.
2004-11-20 chdh:
"$Include" command changed so that the command text is not copied to the output file.
| Class Variable Summary ^TOP |
$subtemplateBasePath
Base path for relative file names of subtemplates (for the $Include command). Default Value:
|
| Inherited Class Variable Summary ^TOP |
| Method Summary ^TOP |
void constructor MiniTemplator ( )
Constructs a MiniTemplator object. |
boolean addBlock ( $blockName )
Adds an instance of a template block. |
boolean blockExists ( $blockName )
Checks whether a block with the specified name exists within the template. |
boolean generateOutput ( )
Generates the HTML page and writes it to the PHP output stream. |
boolean generateOutputToFile ( $fileName )
Generates the HTML page and writes it to a file. |
boolean generateOutputToString ( &$outputString )
Generates the HTML page and writes it to a string. |
boolean readTemplateFromFile ( $fileName )
Reads the template from a file. |
void reset ( )
Clears all variables and blocks. |
boolean setTemplateString ( $templateString )
Assigns a new template string. |
boolean setVariable ( $variableName, $variableValue, [$isOptional = false] )
Sets a template variable. |
boolean setVariableEsc ( $variableName, $variableValue, [$isOptional = false] )
Sets a template variable to an escaped string. |
boolean variableExists ( $variableName )
Checks whether a variable with the specified name exists within the template. |
| Inherited Method Summary ^TOP |
| Variable Detail ^TOP |
This path is prepended to the subtemplate file names. It must be set before readTemplateFromFile or setTemplateString.
public| Method Detail ^TOP |
If the block contains variables, these variables must be set before the block is added. If the block contains subblocks (nested blocks), the subblocks must be added before this block is added. If multiple blocks exist with the specified name, an instance is added for each block occurence.
This method can be used to produce another HTML page with the same template. It is faster than creating another MiniTemplator object, because the template does not have to be parsed again. All variable values are cleared and all added block instances are deleted.
For variables that are used in blocks, the variable value must be set before addBlock is called.
This method is identical to (@link setVariable), except that the characters <, >, &, ' and " of variableValue are replaced by their corresponding HTML/XML character entity codes. For variables that are used in blocks, the variable value must be set before addBlock is called.