Class Template

Description

Template Management for PHP5

The Template engine allows to keep the HTML code in some external files which are completely free of PHP code. This way, it's possible keep logical programmin (PHP code) away from visual structure (HTML or XML, CSS, etc)

If you are familiar with PHP template concept, this class includes these features: auto-detect blocks, auto-clean children blocks, warning when user call for a non-existent block, warning when a mal-formed block is detected, warning when user sets a non existant variable, and other minor features.

Read the tutorial for more details, error messages, etc.

  • version: 1.3
  • author: Rael G.C. (rael.gc@gmail.com)
Method Summary
 Template __construct (string $filename, [boolean $accurate = false])
 void addFile (string $varname, string $filename)
 void clearVar (string $varname)
 void parseBlock (string $block, [boolean $append = false])
 string getContent ()
 void show ()
Methods
Constructor __construct

Creates a new template, using $filename as main file.

When the parameter $accurate is true, blocks will be replaced perfectly (in the parse time), e.g., removing all \t (tab) characters, making the final document an accurate version. This will impact (a lot) the performance. Usefull for files using the <pre> or <code> tags.

Template __construct (string $filename, [boolean $accurate = false])
  • string $filename: file path of the file to be loaded
  • boolean $accurate: true for accurate block parsing
addFile

Put the content of $filename in the template variable identified by $varname

void addFile (string $varname, string $filename)
  • string $varname: existing template var
  • string $filename: path of the file to be loaded
clearVar

Clear the value of a variable.

void clearVar (string $varname)
  • string $varname: var name to be cleaned
parseBlock

Show a block.

This method must be called when a block must be showed. Otherwise, the block will not appear in the resultant content.

If the parameter $append is true, the block content will be appended with the previous content.

void parseBlock (string $block, [boolean $append = false])
  • string $block: the block name to be parsed
  • boolean $append: true if the content must be appended
getContent

Returns the final content.

If you want to see the content in the screen, use Template::show().

string getContent ()
show

Print the final content.

void show ()

Documentation generated on Tue, 26 Feb 2008 07:38:54 -0300 by phpDocumentor 1.3.0RC3