Create a new patTemplate instance.
The constructor accepts the type of the templates as sole parameter. You may choose one of:
The type influences the tags you are using in your templates.
patTemplate
patTemplate
([string $type = 'html'])
-
string
$type: type (either html or tex)
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
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
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.
void
addModuleDir
(string $moduleType, string|array $dir)
-
string
$moduleType: module type
-
string|array
$dir: directory or directories to search.
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 _)
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
add a variable to a template
A variable may also be an indexed array, but _not_ an associative array!
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
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
enable an input filter
input filters are used to modify the template stream before it is split into smaller templates-
boolean
applyInputFilter
(string $filter, [array $params = array()])
-
string
$filter: name of the input filter
-
array
$params: parameters for the input filter
apply input filters that have been set
This is being called by the readers.
string
applyInputFilters
(string $template)
-
string
$template: template
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.
boolean
applyOutputFilter
(string $filter, [array $params = array()])
-
string
$filter: name of the output filter
-
array
$params: parameters for the output filter
clears all templates
void
clearAllTemplates
()
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
Clears a global variable
boolean
clearGlobalVar
(string $varname)
-
string
$varname: name of the global variable
Clears all global variables
boolean
clearGlobalVars
(mixed $varname)
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
clear the value of a variable
boolean
clearVar
(string $template, string $varname)
-
string
$template: name of the template
-
string
$varname: name of the variable
Clear all variables in a template
This clears only variables, but does
boolean
clearVars
(string $template)
-
string
$template: name of the template
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:
Displays useful information about all or named templates
This method breaks BC, as it now awaits an array instead of unlimited parameters.
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
checks wether a template exists
boolean
exists
(string $name)
-
string
$name: name of the template
frees all templates
All memory consumed by the templates will be freed.
void
freeAllTemplates
()
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
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
Get all attributes of a template
array
getAttributes
(string $template)
-
string
$template: name of the template
get default attributes
return
getDefaultAttributes
()
get end tag for variables
string
getEndTag
()
get all global variables
array
getGlobalVars
()
get the include path
void
getIncludePath
()
gets namespace of patTemplate tags
string|array
getNamespace
()
gets an option
mixed
getOption
(string $option)
-
string
$option: option to get
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
gets name of root base for the templates
mixed
getRoot
()
get start tag for variables
string
getStartTag
()
get the value of a variable
string
getVar
(string $template, string $varname)
-
string
$template: name of the template
-
string
$varname: name of the variable
loads a patTemplate module
Modules are located in the patTemplate folder and include:
- Readers
- Caches
- Variable Modifiers
- Filters
- Functions
- Stats
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
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.
boolean
loadTemplate
(string $template)
-
string
$template: template name
open any input and load content into template
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,
checks whether a module exists.
Modules are located in the patTemplate folder and include:
- Readers
- Caches
- Variable Modifiers
- Filters
- Functions
- Stats
boolean
moduleExists
(string $moduleType, string $moduleName)
-
string
$moduleType: moduleType (Reader|TemplateCache|Modifier|OutputFilter|InputFilter)
-
string
$moduleName: moduleName
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.
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)
void
parseTemplate
(string $template, [string $mode = 'w'])
-
string
$template: name of the template
-
string
$mode: mode for the parsing
Prepare a template
This can be used if you want to add variables to a template, that has not been loaded yet.
void
prepareTemplate
(string $name)
-
string
$name: template name
open a file and parse for patTemplate tags
true,
readTemplatesFromFile
(name $filename)
-
name
$filename: of the file
open any input and parse for patTemplate tags
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.
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
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
sets name of directory where templates are stored
void
setBasedir
(string $basedir)
-
string
$basedir: dir where templates are stored
set default attribute
void
setDefaultAttribute
(string $name, mixed $value)
-
string
$name: attribute name
-
mixed
$value: attribute value
set default attributes
void
setDefaultAttributes
(array $attributes)
-
array
$attributes: attributes
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.
void
setNamespace
(string|array $ns)
-
string|array
$ns: namespace(s)
sets an option
Currently, the following options are supported
- maintainBc (true|false)
- namespace (string)
void
setOption
(string $option, string $value)
-
string
$option: option to set
-
string
$value: value of the option
sets root base for the template
The parameter depends on the reader you are using.
void
setRoot
(string $root)
-
string
$root: root base of the templates
set the start and end tag for variables
boolean
setTags
(string $startTag, string $endTag)
-
string
$startTag: start tag
-
string
$endTag: end tag
set the type for the templates
boolean
setType
(string $type)
-
string
$type: type (html or tex)
enable a template cache
A template cache will improve performace, as the templates do not have to be read on each request.
boolean
useTemplateCache
(string $cache, [array $params = array()])
-
string
$cache: name of the template cache
-
array
$params: parameters for the template cache