Caution: This documentation is for eZ Publish legacy, from version 3.x to 6.x.
For 5.x documentation covering Platform see eZ Documentation Center, for difference between legacy and Platform see 5.x Architecture overview.

Functions and operators

The eZ publish template language offers a collection of various functions and operators that can be used to carry out different tasks. In addition, it is possible to extend the system by creating custom operators for special needs. Custom operators have to be programmed in PHP.

Template functions

A function takes a set of named parameters, carries out a specific task and returns a result. It can be called anywhere in a template using the following syntax:

{function_name parameter1=value1 parameter2=value2 ...}

A function may take none, one or several parameters. The parameters must be specified after the function name, separated by spaces. Since each parameter is specified using the parameter's name, the parameters can be provided in any order. Each parameter must be assigned a value using the equal sign. The following illustration shows the typical usage of a commonly used function.

Template function

Typical components of a function call.

The example above calls the "node_view_gui" function. This function displays a node by including the template that is associated with the view mode. The node is specified using the "content_node" parameter. The desired view mode is specified using the "view" parameter.

Template operators

An operator takes unnamed parameters, carries out a specific task and returns a result. In addition, an operator is capable of handling a parameter which is passed to it using a pipe. It can be called anywhere in a template using the following syntax:

{$input_parameter|operator_name( parameter1, parameter2 ... )}

Because the operator only takes unnamed parameters, the parameters must be specified in the order dictated by the operator's documentation page. In addition, the parameters must be separated by commas. The following illustration shows the typical usage of a commonly used operator.

Typical components of a template operator call.

Typical components of a template operator call.

The example above demonstrates the usage of the "datetime" operator. This operator can be used to convert a UNIX timestamp to a human readable format. The timestamp is provided by the $yesterday_evening variable as the input parameter. The first parameter tells the operator that the output should be formatted using a custom schema. The schema is defined by the second parameter (hours : minutes).

Piping

An operator takes input on the left hand side and produces output on the right hand side. A collection of operators can be glued together using pipes. A pipe makes sure that the output from one operator is presented as the input parameter to another operator. The following example demonstrates how pipes and operators can be used to create a string.

{concat( 'To ', 'The ' )|prepend( 'Back ' )|append( 'Future' )}

The following output will be produced:

Back To The Future

Balazs Halasy (14/09/2010 11:25 am)

Geir Arne Waaler (28/09/2010 11:29 am)


Comments

  • My own functions?

    Can I declare my own functions?
    • Re: My own functions?

      Yes - use the $eZTemplateFunctionArray variable in a eztemplateautoload.php file in the autoloads dir of an extension