Class: patTemplate
Source Location: /includes/patTemplate/patTemplate.php
Class patTemplate
Property Summary
| string |
$_root |
stores the name of the first template that has been found |
| array |
$_systemVars |
standard system vars that identify pat tools |
| array |
$_vars |
stores all local variables |
Method Summary
| patTemplate |
patTemplate() |
Create a new patTemplate instance. |
| void |
addModuleDir() |
add a directory where patTemplate should search for modules. |
| void |
addObject() |
Adds an object to a template |
| void |
addRows() |
Adds several rows of variables to a template |
| void |
addVar() |
add a variable to a template |
| void |
addVars() |
Adds several variables to a template |
| boolean |
clearVar() |
clear the value of a variable |
| boolean |
clearVars() |
Clear all variables in a template |
| void |
dump() |
Displays useful information about all or named templates |
| boolean |
exists() |
checks wether a template exists |
| string|array |
getNamespace() |
gets namespace of patTemplate tags |
| mixed |
getRoot() |
gets name of root base for the templates |
| string |
getVar() |
get the value of a variable |
| boolean |
loadTemplate() |
load a template that had autoload="off" |
| string |
parseIntoVar() |
parse a template and push the result into a variable of any other template |
| void |
setBasedir() |
sets name of directory where templates are stored |
| void |
setRoot() |
sets root base for the template |
| boolean |
setTags() |
set the start and end tag for variables |
| boolean |
setType() |
set the type for the templates |
| array |
_getDependencies() |
get _all_ dependencies of a template, regardless of the subtemplates |
| boolean |
_hasVariables() |
check, whether a template contains variables |
| string |
__toString() |
Convert the template to its string representation. |
Properties
default attributes for new templates
API Tags:
placeholders, that have been discovered
API Tags:
stores all global variables
API Tags:
input filters that should be used
API Tags:
directories, where modules can be stored
API Tags:
loaded modules
Modules are: - Readers
- Caches
- Variable modifiers
- Filters
API Tags:
options for patTemplate
Currently the following options are implemented: - maintainBc defines, whether patTemplate should be backwards compatible.
This means, that you may use 'default' and 'empty' for subtemplates.
API Tags:
output filters that should be used
API Tags:
stores the name of the first template that has been found
API Tags:
standard system vars that identify pat tools
stores all template names
API Tags:
stores all template data
API Tags:
template cache, that should be used
API Tags:
stores all local variables
API Tags:
Methods
patTemplate patTemplate(
[string
$type = 'html']
)
|
|
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.
Parameters:
|
string |
$type: |
type (either html or tex) |
API Tags:
boolean addGlobalVar(
string
$varname, string
$value
)
|
|
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.
Parameters:
|
string |
$varname: |
name of the global variable |
|
string |
$value: |
value of the variable |
API Tags:
boolean addGlobalVars(
array
$variables, [string
$prefix = '']
)
|
|
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.
Parameters:
|
array |
$variables: |
array containing the variables |
|
string |
$prefix: |
prefix for variable names |
API Tags:
void addModuleDir(
string
$moduleType, string|array
$dir
)
|
|
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.
Parameters:
|
string |
$moduleType: |
module type |
|
string|array |
$dir: |
directory or directories to search. |
API Tags:
void addObject(
string
$template, object|array
$object, [string
$prefix = ''], [boolean
$ignorePrivate = false]
)
|
|
Adds an object to a template
All properties of the object will be available as template variables.
Parameters:
|
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 _) |
API Tags:
void addRows(
string
$template, array
$rows, [string
$prefix = '']
)
|
|
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
Parameters:
|
string |
$template: |
name of the template |
|
array |
$rows: |
array containing assotiative arrays with variable/value pairs |
|
string |
$prefix: |
prefix for all variable names |
API Tags:
void addVar(
string
$template, string
$varname, mixed
$value
)
|
|
add a variable to a template
A variable may also be an indexed array, but _not_ an associative array!
Parameters:
|
string |
$template: |
name of the template |
|
string |
$varname: |
name of the variable |
|
mixed |
$value: |
value of the variable |
API Tags:
void addVars(
string
$template, array
$variables, [string
$prefix = '']
)
|
|
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
Parameters:
|
string |
$template: |
name of the template |
|
array |
$variables: |
assotiative array of the variables |
|
string |
$prefix: |
prefix for all variable names |
API Tags:
boolean applyInputFilter(
string
$filter, [array
$params = array()]
)
|
|
enable an input filter
input filters are used to modify the template stream before it is split into smaller templates-
Parameters:
|
string |
$filter: |
name of the input filter |
|
array |
$params: |
parameters for the input filter |
API Tags:
| Return: | true on success, patError otherwise |
| Access: | public |
string applyInputFilters(
string
$template
)
|
|
apply input filters that have been set
This is being called by the readers.
Parameters:
|
string |
$template: |
template |
API Tags:
| Return: | filtered templeta |
| Access: | public |
boolean applyOutputFilter(
string
$filter, [array
$params = array()], [
$template = null]
)
|
|
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.
Parameters:
|
string |
$filter: |
name of the output filter |
|
array |
$params: |
parameters for the output filter |
|
|
$template: |
|
API Tags:
| Return: | true on success, patError otherwise |
| Access: | public |
void clearAllTemplates(
)
|
|
clears all templates
API Tags:
void clearAttribute(
string
$template, string
$attribute
)
|
|
Clears an attribute of a template
supported attributes: visibilty, loop, parse, unusedvars
Parameters:
|
string |
$template: |
name of the template |
|
string |
$attribute: |
name of the attribute |
API Tags:
boolean clearGlobalVar(
string
$varname
)
|
|
Clears a global variable
Parameters:
|
string |
$varname: |
name of the global variable |
API Tags:
boolean clearGlobalVars(
)
|
|
Clears all global variables
API Tags:
void clearTemplate(
string
$name, [boolean
$recursive = false]
)
|
|
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()
Parameters:
|
string |
$name: |
name of the template |
|
boolean |
$recursive: |
set this to true to clear all child templates, too |
API Tags:
boolean clearVar(
string
$template, string
$varname
)
|
|
clear the value of a variable
Parameters:
|
string |
$template: |
name of the template |
|
string |
$varname: |
name of the variable |
API Tags:
boolean clearVars(
string
$template
)
|
|
Clear all variables in a template
This clears only variables, but does
Parameters:
|
string |
$template: |
name of the template |
API Tags:
boolean displayParsedTemplate(
[string
$name = null], [boolean
$applyFilters = true]
)
|
|
displays a parsed Template
If the template has not been loaded, it will be loaded.
Parameters:
|
string |
$name: |
name of the template |
|
boolean |
$applyFilters: |
whether to apply output filters |
API Tags:
Redefined in descendants as:
void dump(
[mixed
$restrict = null], [string
$dumper = 'Html']
)
|
|
Displays useful information about all or named templates
This method breaks BC, as it now awaits an array instead of unlimited parameters.
Parameters:
|
mixed |
$restrict: |
array of templates that should be dumped, or null if you want all templates to be dumped |
|
string |
$dumper: |
dumper |
API Tags:
boolean exists(
string
$name
)
|
|
checks wether a template exists
Parameters:
|
string |
$name: |
name of the template |
API Tags:
| Return: | true, if the template exists, false otherwise |
| Access: | public |
frees all templates
All memory consumed by the templates will be freed.
API Tags:
void freeTemplate(
string
$name, [boolean
$recursive = false]
)
|
|
frees a template
All memory consumed by the template will be freed.
Parameters:
|
string |
$name: |
name of the template |
|
boolean |
$recursive: |
clear dependencies of the template |
API Tags:
mixed getAttribute(
string
$template, string
$attribute
)
|
|
Gets an attribute of a template
supported attributes: visibilty, loop, parse, unusedvars
Parameters:
|
string |
$template: |
name of the template |
|
string |
$attribute: |
name of the attribute |
API Tags:
array getAttributes(
string
$template
)
|
|
Get all attributes of a template
Parameters:
|
string |
$template: |
name of the template |
API Tags:
| Return: | attributes |
| Access: | public |
return getDefaultAttributes(
)
|
|
get default attributes
API Tags:
| Return: | default attributes |
| Access: | public |
get end tag for variables
API Tags:
| Return: | end tag |
| Access: | public |
get all global variables
API Tags:
| Return: | global variables |
| Access: | public |
get the include path
API Tags:
string|array getNamespace(
)
|
|
gets namespace of patTemplate tags
API Tags:
| Return: | namespace(s) |
| Access: | public |
array getObjectVars(
object
$obj, [boolean
$ignorePrivate = false]
)
|
|
get the vars from an object
Parameters:
|
object |
$obj: |
|
|
boolean |
$ignorePrivate: |
ignore private properties (starting with _) |
API Tags:
mixed getOption(
string
$option
)
|
|
gets an option
Parameters:
|
string |
$option: |
option to get |
API Tags:
| Return: | value of the option |
| Access: | public |
string getParsedTemplate(
[string
$name = null], [boolean
$applyFilters = false]
)
|
|
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.
Parameters:
|
string |
$name: |
name of the template |
|
boolean |
$applyFilters: |
whether to apply output filters |
API Tags:
mixed getRoot(
[
$reader = '__default']
)
|
|
gets name of root base for the templates
Parameters:
API Tags:
| Return: | root base |
| Access: | public |
get start tag for variables
API Tags:
| Return: | start tag |
| Access: | public |
string getVar(
string
$template, string
$varname
)
|
|
get the value of a variable
Parameters:
|
string |
$template: |
name of the template |
|
string |
$varname: |
name of the variable |
API Tags:
| Return: | value of the variable, null if the variable is not set |
| Access: | public |
object &loadModule(
string
$moduleType, string
$moduleName, [array
$params = array()], [
$new = false]
)
|
|
loads a patTemplate module
Modules are located in the patTemplate folder and include: - Readers
- Caches
- Variable Modifiers
- Filters
- Functions
- Stats
Parameters:
|
string |
$moduleType: |
moduleType (Reader|TemplateCache|Modifier|OutputFilter|InputFilter) |
|
string |
$moduleName: |
moduleName |
|
array |
$params: |
parameters for the module |
|
|
$new: |
|
API Tags:
boolean loadTemplate(
string
$template
)
|
|
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.
Parameters:
|
string |
$template: |
template name |
API Tags:
| Return: | true, if template could be loaded |
| Access: | public |
boolean loadTemplateFromInput(
string
$input, [string
$reader = 'File'], [string
$options = null], [
$parseInto = false]
)
|
|
open any input and load content into template
Parameters:
|
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: |
|
API Tags:
| Return: | true, if the template could be parsed, false otherwise |
| Access: | public |
boolean moduleExists(
string
$moduleType, string
$moduleName
)
|
|
checks whether a module exists.
Modules are located in the patTemplate folder and include: - Readers
- Caches
- Variable Modifiers
- Filters
- Functions
- Stats
Parameters:
|
string |
$moduleType: |
moduleType (Reader|TemplateCache|Modifier|OutputFilter|InputFilter) |
|
string |
$moduleName: |
moduleName |
API Tags:
string parseIntoVar(
string
$srcTmpl, boolean
$destTmpl,
$var, [
$append = false]
)
|
|
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.
Parameters:
|
string |
$srcTmpl: |
name of the template |
|
boolean |
$destTmpl: |
if set to true, the value will be appended to the value already stored. |
|
|
$var: |
|
|
|
$append: |
|
API Tags:
void parseTemplate(
string
$template, [string
$mode = 'w']
)
|
|
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)
Parameters:
|
string |
$template: |
name of the template |
|
string |
$mode: |
mode for the parsing |
API Tags:
void placeholderExists(
string
$placeholder, string
$tmpl, [boolean
$cached = true]
)
|
|
checks, whether a placeholder exists in a template
Parameters:
|
string |
$placeholder: |
name of the placeholder |
|
string |
$tmpl: |
name of the template |
|
boolean |
$cached: |
whether to use the cached result of a previous call |
API Tags:
void prepareTemplate(
string
$name
)
|
|
Prepare a template
This can be used if you want to add variables to a template, that has not been loaded yet.
Parameters:
|
string |
$name: |
template name |
API Tags:
true, readTemplatesFromFile(
name
$filename
)
|
|
open a file and parse for patTemplate tags
Parameters:
|
name |
$filename: |
of the file |
API Tags:
| Return: | if the template could be parsed |
| See: | patTemplate::readTemplatesFromInput() |
| Deprecated: | Use patTemplate::readTemplatesFromInput() instead, as the method name is misleading |
| Access: | public |
boolean readTemplatesFromInput(
string
$input, [string
$reader = 'File'], [array
$options = null], [string
$parseInto = null]
)
|
|
open any input and parse for patTemplate tags
Parameters:
|
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. |
API Tags:
| Return: | true, if the template could be parsed, false otherwise |
| Access: | public |
void setAttribute(
string
$template, string
$attribute, mixed
$value
)
|
|
Sets an attribute of a template
supported attributes: visibilty, loop, parse, unusedvars
Parameters:
|
string |
$template: |
name of the template |
|
string |
$attribute: |
name of the attribute |
|
mixed |
$value: |
value of the attribute |
API Tags:
void setAttributes(
string
$template, array
$attributes
)
|
|
Sets several attribute of a template
$attributes has to be a assotiative arrays containing attribute/value pairs supported attributes: visibilty, loop, parse, unusedvars
Parameters:
|
string |
$template: |
name of the template |
|
array |
$attributes: |
attribute/value pairs |
API Tags:
void setBasedir(
string
$basedir
)
|
|
sets name of directory where templates are stored
Parameters:
|
string |
$basedir: |
dir where templates are stored |
API Tags:
| Deprecated: | please use patTemplate::setRoot() instead |
| Access: | public |
void setDefaultAttribute(
string
$name, mixed
$value
)
|
|
set default attribute
Parameters:
|
string |
$name: |
attribute name |
|
mixed |
$value: |
attribute value |
API Tags:
void setDefaultAttributes(
array
$attributes
)
|
|
set default attributes
Parameters:
|
array |
$attributes: |
attributes |
API Tags:
void setNamespace(
string|array
$ns
)
|
|
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.
Parameters:
|
string|array |
$ns: |
namespace(s) |
API Tags:
void setOption(
string
$option, string
$value
)
|
|
sets an option
Currently, the following options are supported - maintainBc (true|false)
- namespace (string)
Parameters:
|
string |
$option: |
option to set |
|
string |
$value: |
value of the option |
API Tags:
void setRoot(
string
$root, [
$reader = '__default']
)
|
|
sets root base for the template
The parameter depends on the reader you are using.
Parameters:
|
string |
$root: |
root base of the templates |
|
|
$reader: |
|
API Tags:
boolean setTags(
string
$startTag, string
$endTag
)
|
|
set the start and end tag for variables
Parameters:
|
string |
$startTag: |
start tag |
|
string |
$endTag: |
end tag |
API Tags:
| Return: | true on success |
| Access: | public |
boolean setType(
string
$type
)
|
|
set the type for the templates
Parameters:
|
string |
$type: |
type (html or tex) |
API Tags:
| Return: | true on success |
| Access: | public |
boolean useTemplateCache(
string
$cache, [array
$params = array()]
)
|
|
enable a template cache
A template cache will improve performace, as the templates do not have to be read on each request.
Parameters:
|
string |
$cache: |
name of the template cache |
|
array |
$params: |
parameters for the template cache |
API Tags:
| Return: | true on success, patError otherwise |
| Access: | public |
boolean _applyModifers(
string
$template, array
&$vars
)
|
|
apply variable modifiers
The variables will be passed by reference.
Parameters:
|
string |
$template: |
name of the template (use modifiers from this template) |
|
array |
&$vars: |
variables to which the modifiers should be applied |
API Tags:
boolean _fetchTemplate(
string
$template
)
|
|
fetch plain template
The template content will be stored in the template configuration so it can be used by other methods.
Parameters:
|
string |
$template: |
template name |
API Tags:
boolean _fetchVariables(
string
$template
)
|
|
fetch variables for a template
The variables will be stored in the template configuration so they can be used by other methods.
Parameters:
|
string |
$template: |
template name |
API Tags:
void _getConditionValue(
string
$template, string
$value, [boolean
$isVar = true]
)
|
|
fetch the value of a condition variable
_fetchVariables() has to be called before this method is being called.
Parameters:
|
string |
$template: |
template name |
|
string |
$value: |
condition value |
|
boolean |
$isVar: |
flag that indicates whether value is the name of the variable that should be resolved |
API Tags:
Information Tags:
| Todo: | split this method into smaller check methods that will be called according to a priority list |
array _getDependencies(
string
$template
)
|
|
get _all_ dependencies of a template, regardless of the subtemplates
Parameters:
|
string |
$template: |
template name |
API Tags:
| Return: | list of all subtemplates |
| Access: | private |
void _handleUnusedVars(
string
$template
)
|
|
handle all unused variables in a template
This is influenced by the 'unusedvars' attribute of the template
Parameters:
API Tags:
boolean _hasVariables(
string
$template
)
|
|
check, whether a template contains variables
Parameters:
|
string |
$template: |
template name |
API Tags:
boolean _initTemplate(
string
$template
)
|
|
Initialize a template
This method checks the variable specifications and copys variables from other templates.
Parameters:
|
string |
$template: |
name of the template |
API Tags:
| Return: | true on success |
| Access: | private |
array|boolean _loadTemplatesFromCache(
string
$input, string
&$reader, array
$options, string
$key
)
|
|
load from template cache
Parameters:
|
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: |
options for the reader |
|
string |
$key: |
cache key |
API Tags:
| Return: | either an array containing the templates, or false |
| Access: | private |
void _parseDependencies(
string
$template
)
|
|
parse all dependencies in a template
Parameters:
API Tags:
boolean _parseGlobals(
string
$template
)
|
|
parse global variables in the template
Parameters:
|
string |
$template: |
name of the template |
API Tags:
void _parseVariables(
string
$template
)
|
|
parse all variables in a template
Parameters:
API Tags:
Convert the template to its string representation.
This method allows you to just echo the patTemplate object in order to display the template. Requires PHP5
echo $tmpl;
API Tags:
|
|