Functions and operators
This part of the 4.x documentation is for eZ Publish 4.0, only reference section is common for all eZ Publish 4.x versions as well as eZ Publish 5.x "LegacyStack", please select the version you are using for the most up to date documentation! |
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](../../../../../var/doc/storage/images/ez_publish/technical_manual/4_0/images/templates/template_function/6125-3-eng-GB/template_function_doc.png)
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.](../../../../../var/doc/storage/images/ez_publish/technical_manual/4_0/images/templates/template_operator/6128-2-eng-GB/template_operator_doc.png)
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 (16/02/2005 10:33 am)
Ricardo Correia (17/04/2013 1:20 pm)
Comments
My own functions?
Monday 19 November 2007 11:10:37 am
Adrien
Re: My own functions?
Tuesday 09 June 2009 5:07:23 pm
Gaetano
Illustrations
Monday 25 May 2009 8:41:17 am
Finn Mathisen