Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: patTemplate

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5

 Class patTemplate

Description

patTemplate

powerful templating engine

Located in /pattemplate/patTemplate.php (line 69)

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

standard system vars that identify pat tools

Methods
Constructor patTemplate (line 236)

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 867)

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 917)

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 453)

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 815)

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 783)

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 625)

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 723)

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 1022)

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 2594)

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 989)

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()], [ $template = null])
  • string $filter: name of the output filter
  • array $params: parameters for the output filter
  • $template
clearAllTemplates (line 2422)

clears all templates

void clearAllTemplates ()
clearAttribute (line 577)

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 881)

Clears a global variable

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

Clears all global variables

boolean clearGlobalVars ()
clearTemplate (line 2384)

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 688)

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 760)

Clear all variables in a template

This clears only variables, but does

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

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 2533)

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 947)

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 2489)

frees all templates

All memory consumed by the templates will be freed.

void freeAllTemplates ()
freeTemplate (line 2444)

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 553)

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 529)

Get all attributes of a template

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

get default attributes

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

get end tag for variables

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

get all global variables

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

get the include path

  • access: public
string getIncludePath ()
getNamespace (line 333)

gets namespace of patTemplate tags

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

gets an option

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

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 307)

gets name of root base for the templates

  • return: root base
  • access: public
mixed getRoot ([ $reader = '__default'])
  • $reader
getStartTag (line 422)

get start tag for variables

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

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 1368)

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()], [ $new = false])
  • string $moduleType: moduleType (Reader|TemplateCache|Modifier|OutputFilter|InputFilter)
  • string $moduleName: moduleName
  • array $params: parameters for the module
  • $new
loadTemplate (line 1327)

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 1288)

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], [ $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,
  • $parseInto
moduleExists (line 1451)

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 2351)

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,  $var, [ $append = false])
  • string $srcTmpl: name of the template
  • boolean $destTmpl: if set to true, the value will be appended to the value already stored.
  • $var
  • $append
parseTemplate (line 1504)

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
placeholderExists (line 2612)

checks, whether a placeholder exists in a template

  • access: public
void placeholderExists (string $placeholder, string $tmpl, [boolean $cached = true])
  • string $placeholder: name of the placeholder
  • string $tmpl: name of the template
  • boolean $cached: whether to use the cached result of a previous call
prepareTemplate (line 602)

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 1044)

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 1060)

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 474)

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 501)

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 283)

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 345)

set default attribute

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

set default attributes

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

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 256)

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 296)

sets root base for the template

The parameter depends on the reader you are using.

  • access: public
void setRoot (string $root, [ $reader = '__default'])
  • string $root: root base of the templates
  • $reader
setTags (line 406)

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 379)

set the type for the templates

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

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 Mon, 05 Mar 2007 21:16:22 +0000 by phpDocumentor 1.3.1