Class patTemplate

Description

patTemplate

powerful templating engine

Located in /includes/patTemplate/patTemplate.php (line 65)


	
			
Direct descendents
Class Description
patTemplate_Compiler Compiler for patTemplate
Variable Summary
array $_systemVars
Method Summary
patTemplate patTemplate ([string $type = 'html'])
boolean addGlobalVar (string $varname, string $value)
boolean addGlobalVars (array $variables, [string $prefix = ''])
void addModuleDir (string $moduleType, string|array $dir)
void addObject (string $template, object|array $object, [string $prefix = ''], [boolean $ignorePrivate = false])
void addRows (string $template, array $rows, [string $prefix = ''])
void addVar (string $template, string $varname, mixed $value)
void addVars (string $template, array $variables, [string $prefix = ''])
boolean applyInputFilter (string $filter, [array $params = array()])
string applyInputFilters (string $template)
boolean applyOutputFilter (string $filter, [array $params = array()])
void clearAttribute (string $template, string $attribute)
boolean clearGlobalVar (string $varname)
boolean clearGlobalVars (mixed $varname)
void clearTemplate (string $name, [boolean $recursive = false])
boolean clearVar (string $template, string $varname)
boolean clearVars (string $template)
boolean displayParsedTemplate ([string $name = null], [boolean $applyFilters = true])
void dump ([mixed $restrict = null], [string $dumper = 'Html'])
boolean exists (string $name)
void freeTemplate (string $name, [boolean $recursive = false])
mixed getAttribute (string $template, string $attribute)
array getAttributes (string $template)
string getEndTag ()
array getGlobalVars ()
void getIncludePath ()
string|array getNamespace ()
mixed getOption (string $option)
string getParsedTemplate ([string $name = null], [boolean $applyFilters = false])
mixed getRoot ()
string getStartTag ()
string getVar (string $template, string $varname)
object &loadModule (string $moduleType, string $moduleName, [array $params = array()], [mixed $new = false])
boolean loadTemplate (string $template)
boolean loadTemplateFromInput (string $input, [string $reader = 'File'], [string $options = null], [mixed $parseInto = false])
boolean moduleExists (string $moduleType, string $moduleName)
string parseIntoVar (string $srcTmpl, boolean $destTmpl, mixed $var, [mixed $append = false])
void parseTemplate (string $template, [string $mode = 'w'])
void prepareTemplate (string $name)
true, readTemplatesFromFile (name $filename)
boolean readTemplatesFromInput (string $input, [string $reader = 'File'], [array $options = null], [string $parseInto = null])
void setAttribute (string $template, string $attribute, mixed $value)
void setAttributes (string $template, array $attributes)
void setBasedir (string $basedir)
void setDefaultAttribute (string $name, mixed $value)
void setDefaultAttributes (array $attributes)
void setNamespace (string|array $ns)
void setOption (string $option, string $value)
void setRoot (string $root)
boolean setTags (string $startTag, string $endTag)
boolean setType (string $type)
boolean useTemplateCache (string $cache, [array $params = array()])
Variables
array $_systemVars = array(
'appName' => 'patTemplate',
'appVersion' => '3.0.0',
'author' => array(
'Stephan Schmidt <schst@php.net>'
))
(line 71)

standard system vars that identify pat tools

Methods
Constructor patTemplate (line 224)

Create a new patTemplate instance.

The constructor accepts the type of the templates as sole parameter. You may choose one of:

  • html (default)
  • tex
The type influences the tags you are using in your templates.

  • access: public
patTemplate patTemplate ([string $type = 'html'])
  • string $type: type (either html or tex)
addGlobalVar (line 851)

Adds a global variable

Global variables are valid in all templates of this object. A global variable has to be scalar, it will be converted to a string.

boolean addGlobalVar (string $varname, string $value)
  • string $varname: name of the global variable
  • string $value: value of the variable
addGlobalVars (line 901)

Adds several global variables

Global variables are valid in all templates of this object.

$variables is an associative array, containing name/value pairs of the variables.

boolean addGlobalVars (array $variables, [string $prefix = ''])
  • array $variables: array containing the variables
  • string $prefix: prefix for variable names
addModuleDir (line 440)

add a directory where patTemplate should search for modules.

You may either pass a string or an array of directories.

patTemplate will be searching for a module in the same order you added them. If the module cannot be found in the custom folders, it will look in patTemplate/$moduleType.

  • access: public
void addModuleDir (string $moduleType, string|array $dir)
  • string $moduleType: module type
  • string|array $dir: directory or directories to search.
addObject (line 799)

Adds an object to a template

All properties of the object will be available as template variables.

void addObject (string $template, object|array $object, [string $prefix = ''], [boolean $ignorePrivate = false])
  • string $template: name of the template
  • object|array $object: object or array of objects
  • string $prefix: prefix for all variable names
  • boolean $ignorePrivate: ignore private properties (starting with _)
addRows (line 767)

Adds several rows of variables to a template

Each Template can have an unlimited amount of its own variables Can be used to add a database result as variables to a template

void addRows (string $template, array $rows, [string $prefix = ''])
  • string $template: name of the template
  • array $rows: array containing assotiative arrays with variable/value pairs
  • string $prefix: prefix for all variable names
addVar (line 612)

add a variable to a template

A variable may also be an indexed array, but _not_ an associative array!

  • access: public
void addVar (string $template, string $varname, mixed $value)
  • string $template: name of the template
  • string $varname: name of the variable
  • mixed $value: value of the variable
addVars (line 707)

Adds several variables to a template

Each Template can have an unlimited amount of its own variables $variables has to be an assotiative array containing variable/value pairs

void addVars (string $template, array $variables, [string $prefix = ''])
  • string $template: name of the template
  • array $variables: assotiative array of the variables
  • string $prefix: prefix for all variable names
applyInputFilter (line 997)

enable an input filter

input filters are used to modify the template stream before it is split into smaller templates-

  • return: true on success, patError otherwise
  • access: public
boolean applyInputFilter (string $filter, [array $params = array()])
  • string $filter: name of the input filter
  • array $params: parameters for the input filter
applyInputFilters (line 2503)

apply input filters that have been set

This is being called by the readers.

  • return: filtered templeta
  • access: public
string applyInputFilters (string $template)
  • string $template: template
applyOutputFilter (line 973)

enable an output filter

Output filters are used to modify the template result before it is sent to the browser.

They are applied, when displayParsedTemplate() is called.

  • return: true on success, patError otherwise
  • access: public
boolean applyOutputFilter (string $filter, [array $params = array()])
  • string $filter: name of the output filter
  • array $params: parameters for the output filter
clearAllTemplates (line 2335)

clears all templates

void clearAllTemplates ()
clearAttribute (line 564)

Clears an attribute of a template

supported attributes: visibilty, loop, parse, unusedvars

void clearAttribute (string $template, string $attribute)
  • string $template: name of the template
  • string $attribute: name of the attribute
clearGlobalVar (line 865)

Clears a global variable

boolean clearGlobalVar (string $varname)
  • string $varname: name of the global variable
clearGlobalVars (line 882)

Clears all global variables

boolean clearGlobalVars (mixed $varname)
clearTemplate (line 2297)

clears a parsed Template

Parsed Content, variables and the loop attribute are cleared

If you will not be using this template anymore, then you should call freeTemplate()

void clearTemplate (string $name, [boolean $recursive = false])
  • string $name: name of the template
  • boolean $recursive: set this to true to clear all child templates, too
clearVar (line 672)

clear the value of a variable

boolean clearVar (string $template, string $varname)
  • string $template: name of the template
  • string $varname: name of the variable
clearVars (line 744)

Clear all variables in a template

This clears only variables, but does

boolean clearVars (string $template)
  • string $template: name of the template
displayParsedTemplate (line 2235)

displays a parsed Template

If the template has not been loaded, it will be loaded.

boolean displayParsedTemplate ([string $name = null], [boolean $applyFilters = true])
  • string $name: name of the template
  • boolean $applyFilters: whether to apply output filters

Redefined in descendants as:
dump (line 2443)

Displays useful information about all or named templates

This method breaks BC, as it now awaits an array instead of unlimited parameters.

  • access: public
void dump ([mixed $restrict = null], [string $dumper = 'Html'])
  • mixed $restrict: array of templates that should be dumped, or null if you want all templates to be dumped
  • string $dumper: dumper
exists (line 931)

checks wether a template exists

  • return: true, if the template exists, false otherwise
  • access: public
boolean exists (string $name)
  • string $name: name of the template
freeAllTemplates (line 2399)

frees all templates

All memory consumed by the templates will be freed.

void freeAllTemplates ()
freeTemplate (line 2357)

frees a template

All memory consumed by the template will be freed.

void freeTemplate (string $name, [boolean $recursive = false])
  • string $name: name of the template
  • boolean $recursive: clear dependencies of the template
getAttribute (line 540)

Gets an attribute of a template

supported attributes: visibilty, loop, parse, unusedvars

mixed getAttribute (string $template, string $attribute)
  • string $template: name of the template
  • string $attribute: name of the attribute
getAttributes (line 516)

Get all attributes of a template

  • return: attributes
  • access: public
array getAttributes (string $template)
  • string $template: name of the template
getDefaultAttributes (line 354)

get default attributes

  • return: default attributes
  • access: public
return getDefaultAttributes ()
getEndTag (line 420)

get end tag for variables

  • return: end tag
  • access: public
string getEndTag ()
getGlobalVars (line 919)

get all global variables

  • return: global variables
  • access: public
array getGlobalVars ()
getIncludePath (line 2489)

get the include path

  • access: public
void getIncludePath ()
getNamespace (line 320)

gets namespace of patTemplate tags

  • return: namespace(s)
  • access: public
string|array getNamespace ()
getOption (line 256)

gets an option

  • return: value of the option
  • access: public
mixed getOption (string $option)
  • string $option: option to get
getParsedTemplate (line 2197)

returns a parsed Template

If the template already has been parsed, it just returns the parsed template. If the template has not been loaded, it will be loaded.

string getParsedTemplate ([string $name = null], [boolean $applyFilters = false])
  • string $name: name of the template
  • boolean $applyFilters: whether to apply output filters
getRoot (line 294)

gets name of root base for the templates

  • return: root base
  • access: public
mixed getRoot ()
getStartTag (line 409)

get start tag for variables

  • return: start tag
  • access: public
string getStartTag ()
getVar (line 641)

get the value of a variable

  • return: value of the variable, null if the variable is not set
  • access: public
string getVar (string $template, string $varname)
  • string $template: name of the template
  • string $varname: name of the variable
loadModule (line 1343)

loads a patTemplate module

Modules are located in the patTemplate folder and include:

  • Readers
  • Caches
  • Variable Modifiers
  • Filters
  • Functions
  • Stats

  • access: public
object &loadModule (string $moduleType, string $moduleName, [array $params = array()], [mixed $new = false])
  • string $moduleType: moduleType (Reader|TemplateCache|Modifier|OutputFilter|InputFilter)
  • string $moduleName: moduleName
  • array $params: parameters for the module
loadTemplate (line 1302)

load a template that had autoload="off"

This is needed, if you change the source of a template and want to load it, after changing the attribute.

  • return: true, if template could be loaded
  • access: public
boolean loadTemplate (string $template)
  • string $template: template name
loadTemplateFromInput (line 1263)

open any input and load content into template

  • return: true, if the template could be parsed, false otherwise
  • access: public
boolean loadTemplateFromInput (string $input, [string $reader = 'File'], [string $options = null], [mixed $parseInto = false])
  • string $input: name of the input (filename, shm segment, etc.)
  • string $reader: driver that is used as reader
  • string $options: name of the template that should be used as a container,
moduleExists (line 1420)

checks whether a module exists.

Modules are located in the patTemplate folder and include:

  • Readers
  • Caches
  • Variable Modifiers
  • Filters
  • Functions
  • Stats

  • access: public
boolean moduleExists (string $moduleType, string $moduleName)
  • string $moduleType: moduleType (Reader|TemplateCache|Modifier|OutputFilter|InputFilter)
  • string $moduleName: moduleName
parseIntoVar (line 2264)

parse a template and push the result into a variable of any other template

If the template already has been parsed, it will just be pushed into the variable. If the template has not been loaded, it will be loaded.

string parseIntoVar (string $srcTmpl, boolean $destTmpl, mixed $var, [mixed $append = false])
  • string $srcTmpl: name of the template
  • boolean $destTmpl: if set to true, the value will be appended to the value already stored.
parseTemplate (line 1451)

parses a template

Parses a template and stores the parsed content. mode can be "w" for write (delete already parsed content) or "a" for append (appends the new parsed content to the already parsed content)

  • access: public
void parseTemplate (string $template, [string $mode = 'w'])
  • string $template: name of the template
  • string $mode: mode for the parsing
prepareTemplate (line 589)

Prepare a template

This can be used if you want to add variables to a template, that has not been loaded yet.

  • access: public
void prepareTemplate (string $name)
  • string $name: template name
readTemplatesFromFile (line 1019)

open a file and parse for patTemplate tags

  • return: if the template could be parsed
  • see: patTemplate::readTemplatesFromInput()
  • deprecated: Use patTemplate::readTemplatesFromInput() instead, as the method name is misleading
  • access: public
true, readTemplatesFromFile (name $filename)
  • name $filename: of the file
readTemplatesFromInput (line 1035)

open any input and parse for patTemplate tags

  • return: true, if the template could be parsed, false otherwise
  • access: public
boolean readTemplatesFromInput (string $input, [string $reader = 'File'], [array $options = null], [string $parseInto = null])
  • string $input: name of the input (filename, shm segment, etc.)
  • string $reader: driver that is used as reader, you may also pass a Reader object
  • array $options: additional options that will only be used for this template
  • string $parseInto: name of the template that should be used as a container, should not be used by public calls.
setAttribute (line 461)

Sets an attribute of a template

supported attributes: visibilty, loop, parse, unusedvars

void setAttribute (string $template, string $attribute, mixed $value)
  • string $template: name of the template
  • string $attribute: name of the attribute
  • mixed $value: value of the attribute
setAttributes (line 488)

Sets several attribute of a template

$attributes has to be a assotiative arrays containing attribute/value pairs supported attributes: visibilty, loop, parse, unusedvars

void setAttributes (string $template, array $attributes)
  • string $template: name of the template
  • array $attributes: attribute/value pairs
setBasedir (line 270)

sets name of directory where templates are stored

  • deprecated: please use patTemplate::setRoot() instead
  • access: public
void setBasedir (string $basedir)
  • string $basedir: dir where templates are stored
setDefaultAttribute (line 332)

set default attribute

  • access: public
void setDefaultAttribute (string $name, mixed $value)
  • string $name: attribute name
  • mixed $value: attribute value
setDefaultAttributes (line 343)

set default attributes

  • access: public
void setDefaultAttributes (array $attributes)
  • array $attributes: attributes
setNamespace (line 309)

sets namespace of patTemplate tags

If you want to use more than one namespace, you may set this to an array. All tags in these namespaces will be treated as patTemplate tags.

  • access: public
void setNamespace (string|array $ns)
  • string|array $ns: namespace(s)
setOption (line 244)

sets an option

Currently, the following options are supported

  • maintainBc (true|false)
  • namespace (string)

  • access: public
void setOption (string $option, string $value)
  • string $option: option to set
  • string $value: value of the option
setRoot (line 283)

sets root base for the template

The parameter depends on the reader you are using.

  • access: public
void setRoot (string $root)
  • string $root: root base of the templates
setTags (line 393)

set the start and end tag for variables

  • return: true on success
  • access: public
boolean setTags (string $startTag, string $endTag)
  • string $startTag: start tag
  • string $endTag: end tag
setType (line 366)

set the type for the templates

  • return: true on success
  • access: public
boolean setType (string $type)
  • string $type: type (html or tex)
useTemplateCache (line 947)

enable a template cache

A template cache will improve performace, as the templates do not have to be read on each request.

  • return: true on success, patError otherwise
  • access: public
boolean useTemplateCache (string $cache, [array $params = array()])
  • string $cache: name of the template cache
  • array $params: parameters for the template cache

Documentation generated on Fri, 4 Mar 2005 13:56:52 +1000 by phpDocumentor 1.3.0RC3