Class Template_PHPLIB

Description

Converted PHPLIB Template class

For those who want to use PHPLIB's fine template class, here's a PEAR conforming class with the original PHPLIB template code from phplib-stable CVS. Original author was Kristian Koehntopp <kris@koehntopp.de>

Located in /htdocs/js/phplayersmenu/lib/PHPLIB.php (line 28)


	
			
Variable Summary
bool $debug
array $file
string $haltOnError
string $root
string $unknowns
string $_lastError
mixed $_varKeys
array $_varVals
Method Summary
Template_PHPLIB Template_PHPLIB ([string $root = "."], [string $unknowns = "remove"], [array $fallback = ""])
finished, finish (string $str)
string get (string $varname)
mixed getUndefined (string $handle)
mixed getVar (mixed $varname)
array getVars ()
bool halt (string $msg)
object PEAR haltMsg (string $msg)
void p (string $varname)
string parse (string $target, string $handle, [boolean $append = false])
bool pParse (string $target, string $handle, [ $append = false])
bool pSubst (string $handle)
void setBlock (string $parent, string $handle, [string $name = ""])
bool setFile (mixed $handle, [string $filename = ""])
bool setRoot (string $root)
void setUnknowns ([string $unknowns = "keep"])
void setVar (string $varname, [string $value = ""], [boolean $append = false])
mixed subst (string $handle)
Variables
bool $debug = false (line 34)

If set, echo assignments

  • access: public
array $file = array() (line 40)

$file[handle] = "filename";

  • access: public
array $file_fallbacks = array() (line 46)

fallback paths that should be defined in a child class

  • access: public
string $haltOnError = "report" (line 78)

"yes" => halt, "report" => report error, continue, "no" => ignore error quietly

  • access: public
string $root = "" (line 52)

Relative filenames are relative to this pathname

  • access: public
string $unknowns = "remove" (line 72)

"remove" => remove undefined variables

"comment" => replace undefined variables with comments "keep" => keep undefined variables

  • access: public
string $_lastError = "" (line 85)

The last error message is retained here

mixed $_varKeys = array() (line 58)
  • access: public
array $_varVals = array() (line 64)

$_varVals[key] = "value";

  • access: public
Methods
Constructor Template_PHPLIB (line 96)

Constructor

  • access: public
Template_PHPLIB Template_PHPLIB ([string $root = "."], [string $unknowns = "remove"], [array $fallback = ""])
  • string $root: template root directory
  • string $unknowns: how to handle unknown variables
  • array $fallback: fallback paths
finish (line 409)

Finish string

  • return: i.e. substituted string
  • access: public
finished, finish (string $str)
  • string $str: string to finish
get (line 442)

Get finished variable

  • return: string with finished variable
string get (string $varname)
  • string $varname: variable to get
getUndefined (line 375)

Get undefined values of a handle

  • return: false if an error occured or the undefined values
  • access: public
mixed getUndefined (string $handle)
  • string $handle: handle name
getVar (line 349)

Return one or more specific variable(s) with their values.

  • return: array of variable names with their values or value of one specific variable
  • access: public
mixed getVar (mixed $varname)
  • mixed $varname: array with variable names or one variable name as a string
getVars (line 331)

Return all defined variables and their values

  • return: with all defined variables and their values
  • access: public
array getVars ()
halt (line 538)

Error function. Halt template system with message to show

  • access: public
bool halt (string $msg)
  • string $msg: message to show
haltMsg (line 561)

printf error message to show

  • return: error object
  • access: public
object PEAR haltMsg (string $msg)
  • string $msg: message to show
p (line 430)

Print variable to the browser

  • access: public
void p (string $varname)
  • string $varname: name of variable to print
parse (line 291)

Parse handle into target

Parses handle $handle into $target, eventually appending handle at $target if $append is defined as TRUE.

  • return: parsed handle
  • access: public
string parse (string $target, string $handle, [boolean $append = false])
  • string $target: target handle to parse into
  • string $handle: which handle should be parsed
  • boolean $append: append it to $target or not?
pParse (line 319)

Same as parse, but printing it.

  • access: public
bool pParse (string $target, string $handle, [ $append = false])
  • string $handle: handle which should be parsed
  • string $target: target to parse into
  • $append
pSubst (line 272)

Same as subst but printing the result

  • return: always false
  • access: public
bool pSubst (string $handle)
  • string $handle: handle of template
setBlock (line 196)

Set a block in the appropriate template handle

By setting a block like that:

&lt;!-- BEGIN blockname --&gt; html code &lt;!-- END blockname --&gt;

you can easily do repeating HTML code, i.e. output database data nice formatted into a HTML table where each DB row is placed into a HTML table row which is defined in this block. It extracts the template $handle from $parent and places variable {$name} instead.

  • access: public
void setBlock (string $parent, string $handle, [string $name = ""])
  • string $parent: parent handle
  • string $handle: block name handle
  • string $name: variable substitution name
setFile (line 155)

Set appropriate template files

With this method you set the template files you want to use. Either you supply an associative array with key/value pairs where the key is the handle for the filname and the value is the filename itself, or you define $handle as the file name handle and $filename as the filename if you want to define only one template.

  • access: public
bool setFile (mixed $handle, [string $filename = ""])
  • mixed $handle: handle for a filename or array with handle/name value pairs
  • string $filename: name of template file
setRoot (line 110)

Sets the template directory

  • access: public
bool setRoot (string $root)
  • string $root: new template directory
setUnknowns (line 135)

What to do with unknown variables

three possible values:

  • "remove" will remove unknown variables (don't use this if you define CSS in your page)
  • "comment" will replace undefined variables with comments
  • "keep" will keep undefined variables as-is

  • access: public
void setUnknowns ([string $unknowns = "keep"])
  • string $unknowns: unknowns
setVar (line 224)

Set corresponding substitutions for placeholders

  • access: public
void setVar (string $varname, [string $value = ""], [boolean $append = false])
  • string $varname: name of a variable that is to be defined or an array of variables with value substitution as key/value pairs
  • string $value: value of that variable
  • boolean $append: if true, the value is appended to the variable's existing value
subst (line 254)

Substitute variables in handle $handle

  • return: string substituted content of handle
  • access: public
mixed subst (string $handle)
  • string $handle: name of handle

Documentation generated on Fri, 22 May 2009 19:10:16 +1000 by phpDocumentor 1.4.1