The main manager for templates.
More...
List of all members.
|
Public Methods |
| eZTemplate () |
& | leftDelimiter () |
& | rightDelimiter () |
| setLeftDelimiter ($delim) |
| setRightDelimiter ($delim) |
| display ($template=false,$extraParameters=false) |
& | fetch ($template=false,$extraParameters=false) |
& | load ($uri,$extraParameters=false) |
& | loadURIRoot ($uri,$displayErrors=true,&$extraParameters) |
& | resourceFor (&$uri,&$res,&$template) |
| emptyVariable () |
& | elementValue (&$dataElements,$rootNamespace,$currentNamespace,$placement=false,$checkExistance=false) |
& | variableElementValue (&$data,$def_nspace) |
| attributeValue (&$data,$nspace) |
& | variableText (&$var,$namespace="",$attrs=array()) |
| operatorParameterList ($name) |
| doOperator (&$element,&$namespace,&$current_nspace,&$value,&$operatorName,&$operatorParameters,&$named_params) |
& | doFunction (&$name,&$func_obj,$nspace,$current_nspace) |
| setVariable ($var,$val,$namespace="") |
| setVariableRef ($var,&$val,$namespace="") |
| unsetVariable ($var,$namespace="") |
| hasVariable ($var,$namespace="",$attrs=array()) |
& | variable ($var,$namespace="",$attrs=array()) |
& | variableAttribute (&$var,$attrs) |
| registerFunctions (&$functionObject) |
| registerFunction ($func_name,&$func_obj) |
| registerLiteral ($func_name) |
| unregisterLiteral ($func_name) |
| registerOperators (&$operatorObject) |
| registerOperator ($op_name,&$op_obj) |
| unregisterOperator ($op_name) |
| registerFilter () |
| registerResource (&$res) |
| unregisterResource ($res_name) |
| setShowDetails ($show) |
| missingParameter ($name,$param) |
| extraParameters ($name,$count,$maxCount) |
| undefinedVariable ($name,$var) |
| undefinedFunction ($func_name) |
| warning ($name,$txt,$placement=false) |
| error ($name,$txt,$placement=false) |
| setIncludeText ($uri,&$text) |
| setIncludeOutput ($uri,&$output) |
| autoloadPathList () |
| setAutoloadPathList ($pathList) |
| autoload () |
| resetVariables () |
& | instance () |
& | ini () |
Static Public Methods |
| isDebugEnabled () |
| setIsDebugEnabled ($debug) |
Public Attributes |
| Resources |
| Associative array of resource objects.
|
| DefaultResource |
| Reference to the default resource object.
|
| Text |
| The original template text.
|
| IncludeText |
| Included texts, usually performed by custom functions.
|
| IncludeOutput |
| Included outputs, usually performed by custom functions.
|
| TimeStamp |
| The timestamp of the template when it was last modified.
|
| LDelim |
| The left delimiter used for parsing.
|
| RDelim |
| The right delimiter used for parsing.
|
| Tree |
| The resulting object tree of the template.
|
| Variables |
| An associative array of template variables.
|
| Operators |
| An associative array of operators.
|
| Functions |
| An associative array of functions.
|
| FunctionAttributes |
| An associative array of function attributes.
|
| Literals |
| An associative array of literal tags.
|
| ShowDetails = false |
| True if output details is to be shown.
|
Detailed Description
The main manager for templates.
The template systems allows for separation of code and layout by moving the layout part into template files. These template files are parsed and processed with template variables set by the PHP code.
The template system in itself is does not do much, it parses template files according to a rule set sets up a tree hierarchy and process the data using functions and operators. The standard template system comes with only a few functions and no operators, it is meant for these functions and operators to be specified by the users of the template system. But for simplicity a few help classes is available which can be easily enabled.
The classes are:
To enable these functions and operator use registerFunction and registerOperator.
In keeping with the spirit of being simple the template system does not know how to get the template files itself. Instead it relies on resource handlers, these handlers fetches the template files using different kind of transport mechanism. For simplicity a default resource class is available, eZTemplateFileResource fetches templates from the filesystem.
The parser process consists of three passes, each pass adds a new level of complexity. The first pass strips text from template blocks which starts with a left delimiter and ends with a right delimiter (default is { and } ), and places them in an array. The second pass iterates the text and block elements and removes newlines from text before function blocks and text after function blocks. The third pass builds the tree according the function rules.
Processing is done by iterating over the root of the tree, if a text block is found the text is appended to the result text. If a variable or contant is it's data is extracted and any operators found are run on it before fetching the result and appending it to the result text. If a function is found the function is called with the parameters and it's up to the function handle children if any.
Constants and template variables will usually be called variables since there's little difference. A template variable expression will start with a $ and consists of a namespace (optional) a name and attribues(optional). The variable expression exists in the "root" namespace, has the name "var" and uses the attribute "attr1". Some functions will create variables on demand, to avoid name conflicts namespaces were introduced, each function will place the new variables in a namespace specified in the template file. Attribues are used for fetching parts of the variable, for instance an element in an array or data in an object. Since the syntax is the same for arrays and objects the PHP code can use simple arrays when speed is required, the template code will not care. A different syntax is also available when you want to access an attribute using a variable. For instance , if the variable $attr_var contains "attr1" it would access the same attribute as in the first example.
The syntax for operators is a | and a name, optionally parameters can be specified with ( and ) delimited with ,. Valid operators are .
Functions look a lot like HTML/XML tags. The function consists of a name and parameters which are assigned using the param=value syntax. Some parameters may be required while others may be optionally, the exact behaviour is specified by each function. Valid functions are "section name=abc loop=4"
Example of usage:
$tpl =& eZTemplate::instance();
$tpl->registerOperators( new eZTemplatePHPOperator( array( "upcase" => "strtoupper",
"reverse" => "strrev" ) ) );
$tpl->registerOperators( new eZTemplateLocaleOperator() );
$tpl->registerFunction( "section", new eZTemplateSectionFunction( "section" ) );
$tpl->registerFunctions( new eZTemplateDelimitFunction() );
$tpl->setVariable( "my_var", "{this value set by variable}", "test" );
$tpl->setVariable( "my_arr", array( "1st", "2nd", "third", "fjerde" ) );
$tpl->setVariable( "multidim", array( array( "a", "b" ),
array( "c", "d" ),
array( "e", "f" ),
array( "g", "h" ) ) );
class mytest
{
function mytest( $n, $s )
{
$this->n = $n;
$this->s = $s;
}
function hasAttribute( $attr )
{
return ( $attr == "name" || $attr == "size" );
}
function &attribute( $attr )
{
switch ( $attr )
{
case "name";
return $this->n;
case "size";
return $this->s;
default:
return null;
}
}
};
$tpl->setVariable( "multidim_obj", array( new mytest( "jan", 200 ),
new mytest( "feb", 200 ),
new mytest( "john", 200 ),
new mytest( "doe", 50 ) ) );
$tpl->setVariable( "curdate", mktime() );
$tpl->display( "lib/eztemplate/example/test.tpl" );
{section name=outer loop=4}
123
{delimit}::{/delimit}
{/section}
{literal test=1} This is some {blah arg1="" arg2="abc" /} {/literal}
<title>This is a test</title>
<table border="1">
<tr><th>{$test:my_var}
{"some text!!!"|upcase|reverse}</th></tr>
{section name=abc loop=$my_arr}
<tr><td>{$abc:item}</td></tr>
{/section}
</table>
<table border="1">
{section name=outer loop=$multidim}
<tr>
{section name=inner loop=$outer:item}
<td>{$inner:item}</td>
{/section}
</tr>
{/section}
</table>
<table border="1">
{section name=outer loop=$multidim_obj}
<tr>
<td>{$outer:item.name}</td>
<td>{$outer:item.size}</td>
</tr>
{/section}
</table>
{section name=outer loop=$nonexistingvar}
<b><i>Dette skal ikke vises</b></i>
{section-else}
<b><i>This is shown when the {ldelim}$loop{rdelim} variable is non-existant</b></i>
{/section}
Denne koster {1.4|l10n(currency)}<br>
{-123456789|l10n(number)}<br>
{$curdate|l10n(date)}<br>
{$curdate|l10n(shortdate)}<br>
{$curdate|l10n(time)}<br>
{$curdate|l10n(shorttime)}<br>
{include file="test2.tpl"/}
Definition at line eztemplate.php.
Constructor & Destructor Documentation
eZTemplate::eZTemplate |
( |
|
) |
|
|
|
Intializes the template with left and right delimiters being { and }, and a file resource. The literal tag "literal" is also registered.
Definition at line eztemplate.php.
References Variables.
Referenced by instance(). |
Member Function Documentation
eZTemplate::attributeValue |
( |
&$ |
data, |
|
|
$ |
nspace |
|
) |
|
|
eZTemplate::autoloadPathList |
( |
|
) |
|
|
|
- Returns:
-
the path list which is used for autoloading functions and operators.
Definition at line eztemplate.php.
Referenced by autoload(). |
eZTemplate::display |
( |
$ |
template = false, |
|
|
$ |
extraParameters = false |
|
) |
|
|
|
Fetches the result of the template file and displays it. If $template is supplied it will load this template file first.
Definition at line eztemplate.php.
References ShowDetails. |
& eZTemplate::doFunction |
( |
&$ |
name, |
|
|
&$ |
func_obj, |
|
|
$ |
nspace, |
|
|
$ |
current_nspace |
|
) |
|
|
eZTemplate::doOperator |
( |
&$ |
element, |
|
|
&$ |
namespace, |
|
|
&$ |
current_nspace, |
|
|
&$ |
value, |
|
|
&$ |
operatorName, |
|
|
&$ |
operatorParameters, |
|
|
&$ |
named_params |
|
) |
|
|
|
Tries to run the operator $operatorName with parameters $operatorParameters on the value $value.
Definition at line eztemplate.php.
References warning(). |
& eZTemplate::elementValue |
( |
&$ |
dataElements, |
|
|
$ |
rootNamespace, |
|
|
$ |
currentNamespace, |
|
|
$ |
placement = false, |
|
|
$ |
checkExistance = false |
|
) |
|
|
eZTemplate::emptyVariable |
( |
|
) |
|
|
eZTemplate::error |
( |
$ |
name, |
|
|
$ |
txt, |
|
|
$ |
placement = false |
|
) |
|
|
eZTemplate::extraParameters |
( |
$ |
name, |
|
|
$ |
count, |
|
|
$ |
maxCount |
|
) |
|
|
& eZTemplate::fetch |
( |
$ |
template = false, |
|
|
$ |
extraParameters = false |
|
) |
|
|
|
Tries to fetch the result of the template file and returns it. If $template is supplied it will load this template file first.
Definition at line eztemplate.php.
References ShowDetails.
Referenced by display(). |
eZTemplate::hasVariable |
( |
$ |
var, |
|
|
$ |
namespace = "", |
|
|
$ |
attrs = array() |
|
) |
|
|
|
Returns true if the variable $var is set in namespace $namespace, if $attrs is supplied alle attributes must exist for the function to return true.
Definition at line eztemplate.php.
References Variables.
Referenced by variableElementValue(). |
& eZTemplate::instance |
( |
|
) |
|
|
|
Returns the globale template instance, creating it if it does not exist.
Definition at line eztemplate.php.
References eZTemplate(). |
eZTemplate::isDebugEnabled |
( |
|
) |
[static] |
|
|
- Returns:
-
true if debugging of internals is enabled, this will display which files are loaded and when cache files are created. Set the option with setIsDebugEnabled().
Definition at line eztemplate.php.
Referenced by resourceFor(). |
& eZTemplate::leftDelimiter |
( |
|
) |
|
|
& eZTemplate::load |
( |
$ |
uri, |
|
|
$ |
extraParameters = false |
|
) |
|
|
& eZTemplate::loadURIRoot |
( |
$ |
uri, |
|
|
$ |
displayErrors = true, |
|
|
&$ |
extraParameters |
|
) |
|
|
|
Loads the template using the URI $uri and returns a structure with the text and timestamp, false otherwise. The structure keys are:
- "text", the text.
- "time-stamp", the timestamp.
Definition at line eztemplate.php.
References warning().
Referenced by load(). |
eZTemplate::missingParameter |
( |
$ |
name, |
|
|
$ |
param |
|
) |
|
|
|
Outputs a warning about the parameter $param missing for function/operator $name.
Definition at line eztemplate.php.
References warning(). |
eZTemplate::operatorParameterList |
( |
$ |
name |
) |
|
|
eZTemplate::registerFilter |
( |
|
) |
|
|
eZTemplate::registerFunction |
( |
$ |
func_name, |
|
|
&$ |
func_obj |
|
) |
|
|
|
Registers the function $func_name to be bound to object $func_obj. If the object has a function called attributeList() it is used for registering function attributes. The function returns an associative array with each key being the name of the function and the value being a boolean. If the boolean is true the function will have children.
Definition at line eztemplate.php.
References Functions. |
eZTemplate::registerFunctions |
( |
&$ |
functionObject |
) |
|
|
|
Registers the functions supplied by the object $functionObject. The object must have a function called functionList() which returns an array of functions this object handles. If the object has a function called attributeList() it is used for registering function attributes. The function returns an associative array with each key being the name of the function and the value being a boolean. If the boolean is true the function will have children.
Definition at line eztemplate.php. |
eZTemplate::registerLiteral |
( |
$ |
func_name |
) |
|
|
eZTemplate::registerOperator |
( |
$ |
op_name, |
|
|
&$ |
op_obj |
|
) |
|
|
|
Registers the operator $op_name to use the object $op_obj.
Definition at line eztemplate.php.
References Operators. |
eZTemplate::registerOperators |
( |
&$ |
operatorObject |
) |
|
|
|
Registers the operators supplied by the object $operatorObject. The function operatorList() must return an array of operator names.
Definition at line eztemplate.php. |
eZTemplate::registerResource |
( |
&$ |
res |
) |
|
|
|
Registers a new resource object $res. The resource object take care of fetching templates using an URI.
Definition at line eztemplate.php.
References warning().
Referenced by eZTemplate(). |
eZTemplate::resetVariables |
( |
|
) |
|
|
& eZTemplate::resourceFor |
( |
&$ |
uri, |
|
|
&$ |
res, |
|
|
&$ |
template |
|
) |
|
|
|
Returns the resource object for URI $uri. If a resource type is specified in the URI it is extracted and set in $res. The template name is set in $template without any resource specifier. To specify a resource the name and a ":" is prepended to the URI, for instance file:my.tpl. If no resource type is found the URI the default resource handler is used.
Definition at line eztemplate.php.
References eZDebug::writeNotice().
Referenced by loadURIRoot(). |
& eZTemplate::rightDelimiter |
( |
|
) |
|
|
eZTemplate::setAutoloadPathList |
( |
$ |
pathList |
) |
|
|
|
Sets the path list for autoloading.
Definition at line eztemplate.php. |
eZTemplate::setIncludeOutput |
( |
$ |
uri, |
|
|
&$ |
output |
|
) |
|
|
eZTemplate::setIncludeText |
( |
$ |
uri, |
|
|
&$ |
text |
|
) |
|
|
eZTemplate::setIsDebugEnabled |
( |
$ |
debug |
) |
[static] |
|
|
Sets whether internal debugging is enabled or not.
Definition at line eztemplate.php. |
eZTemplate::setLeftDelimiter |
( |
$ |
delim |
) |
|
|
eZTemplate::setRightDelimiter |
( |
$ |
delim |
) |
|
|
eZTemplate::setShowDetails |
( |
$ |
show |
) |
|
|
|
Sets whether detail output is used or not. Detail output is useful for debug output where you want to examine the template and the output text.
Definition at line eztemplate.php.
References ShowDetails. |
eZTemplate::setVariable |
( |
$ |
var, |
|
|
$ |
val, |
|
|
$ |
namespace = "" |
|
) |
|
|
eZTemplate::setVariableRef |
( |
$ |
var, |
|
|
&$ |
val, |
|
|
$ |
namespace = "" |
|
) |
|
|
|
Sets the template variable $var to the value $val. - Note:
-
This sets the variable using reference
- See also:
-
setVariable
Definition at line eztemplate.php.
References Variables. |
eZTemplate::undefinedFunction |
( |
$ |
func_name |
) |
|
|
|
Outputs an error about the template function $func_name being undefined.
Definition at line eztemplate.php.
References error(). |
eZTemplate::undefinedVariable |
( |
$ |
name, |
|
|
$ |
var |
|
) |
|
|
|
Outputs a warning about the variable $var being undefined.
Definition at line eztemplate.php.
References warning(). |
eZTemplate::unregisterLiteral |
( |
$ |
func_name |
) |
|
|
|
Removes the literal tag $func_name.
Definition at line eztemplate.php. |
eZTemplate::unregisterOperator |
( |
$ |
op_name |
) |
|
|
eZTemplate::unregisterResource |
( |
$ |
res_name |
) |
|
|
eZTemplate::unsetVariable |
( |
$ |
var, |
|
|
$ |
namespace = "" |
|
) |
|
|
|
Removes the template variable $var. If the variable does not exists an error is output.
Definition at line eztemplate.php.
References warning(). |
& eZTemplate::variable |
( |
$ |
var, |
|
|
$ |
namespace = "", |
|
|
$ |
attrs = array() |
|
) |
|
|
|
Returns the content of the variable $var using namespace $namespace, if $attrs is supplied the result of the attributes is returned.
Definition at line eztemplate.php.
References Variables.
Referenced by variableElementValue(). |
& eZTemplate::variableAttribute |
( |
&$ |
var, |
|
|
$ |
attrs |
|
) |
|
|
|
Returns the attribute(s) of the template variable $var, $attrs is an array of attribute names to use iteratively for each new variable returned.
Definition at line eztemplate.php. |
& eZTemplate::variableElementValue |
( |
&$ |
data, |
|
|
$ |
def_nspace |
|
) |
|
|
|
Returns the value of the template variable $data, or null if no defined variable for that name.
Definition at line eztemplate.php.
References warning(). |
& eZTemplate::variableText |
( |
&$ |
var, |
|
|
$ |
namespace = "", |
|
|
$ |
attrs = array() |
|
) |
|
|
|
Helper function for creating a displayable text for a variable.
Definition at line eztemplate.php. |
eZTemplate::warning |
( |
$ |
name, |
|
|
$ |
txt, |
|
|
$ |
placement = false |
|
) |
|
|
The documentation for this class was generated from the following file:
|