Path

ez components / documentation / api reference / 2006.2 / template


eZ Components 2006.2

Template: ezcTemplate

[ Tutorial ] [ EBNF ] [ Functions ] [ Syntax ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

Class: ezcTemplate

The ezcTemplate class provides the main interface for processing templates. [source]
The ezcTemplate class compiles a source template (*.ezt) to PHP code, executes the PHP code, and returns the output. The generated PHP code will be stored on disk as a compiled template.
If a compiled template already exists of the to process template, the ezcTemplate class executes directly the compiled template; thus omitting the compile step.
The location for the source templates and compiled templates among other things are specified in the ezcTemplateConfiguration configuration object. A default configuration is always present and can be accessed via the $configuration property.
Usually one configuration object will be enough, since most of the templates will use the same configuration settings. If for some reason, other configuration settings are needed:
  • Another ezcTemplateConfiguration object can be assigned to the $configuration property.
  • Another ezcTemplateConfiguration object can be given to the process method. This method will use the given configuration instead.
The properties $send and $receive are available to set the variables that are set in and retrieved from the template.
The next example demonstrates how a template variable is set and retrieved:
1.  <?php
2.  $t new ezcTemplate();
3.  
4.  $t->send->mySentence "Hello world";
5.  echo $t->process"calc_sentence_length.ezt" );
6.  
7.  $number $t->receive->length;
8.  ?>
The template code:
1.  {use $mySentence ""}
2.  
3.  {var $length str_len$mySentence )}
4.  {return $length}

Method Summary

public ezcTemplate __construct( )
Intializes the ezcTemplate with the default settings.
public void generateOptionHash( )
Generates a unique hash from the current options.
public string process( $location, [$config = null] )
Processes the specified template source and returns the output string.
public mixed __get( $name )
Returns the value of the property $name.
public void __isset( $name )
Returns true if the property $name is set, otherwise false.
public void __set( $name, $value )
Sets the property $name to $value.

Methods

__construct

ezcTemplate __construct( )
Intializes the ezcTemplate with the default settings.

generateOptionHash

void generateOptionHash( )
Generates a unique hash from the current options.

process

string process( $location, [ezcTemplateConfiguration $config = null] )
Processes the specified template source and returns the output string.
Note: The first time a template is accessed it needs to be compiled so the execution time will be higher than subsequent calls.

Parameters

Name Type Description
$location  
$config ezcTemplateConfiguration  

Throws

ClassDescription
ezcTemplateParserException If the template could not be compiled.
ezcTemplateFileNotWriteableException If the directory could not be created.

__get

mixed __get( string $name )
Returns the value of the property $name.
The properties that can be retrieved are:
  • ezcTemplateVariableCollection send : Contains the variables that are send to the template.
  • ezcTemplateVariableCollection receive : Contains the variables that are returned by the template.
  • ezcTemplateConfiguration configuration : Contains the template configuration.
  • string output : The output of the processed template.
  • string compiledTemplatePath : The path of the compiled template.
  • tstTree : The generated tstTree (debug).
  • astTree : The generated astTree (debug).

Parameters

Name Type Description
$name string  

Throws

ClassDescription
ezcBasePropertyNotFoundException if the property does not exist.

__isset

void __isset( $name )
Returns true if the property $name is set, otherwise false.

Parameters

Name Type Description
$name  

__set

void __set( string $name, mixed $value )
Sets the property $name to $value.
The properties that can be set are:
  • ezcTemplateVariableCollection send : Contains the variables that are send to the template.
  • ezcTemplateConfiguration configuration : Contains the template configuration.

Parameters

Name Type Description
$name string  
$value mixed  

Throws

ClassDescription
ezcBasePropertyNotFoundException if the property does not exist.

Last updated: Thu, 01 Nov 2007