Skip to the content
Documentation

Functions and operators

No ratings yet

Template code calls two kinds of building blocks: functions, which do something in the template (loop, include, define a variable, show an attribute), and operators, which take values and return a value. Both are registered by the kernel, its libraries and the extensions; the reference pages below are generated from that registration, so they list exactly what an installation has.

Template functions

A function is called with its name and named parameters, in any order, separated by spaces. Many have a closing tag:

{include uri='design:parts/menu.tpl' current=$node}
{attribute_view_gui attribute=$node.data_map.body}
{node_view_gui content_node=$child view='line'}
{foreach $items as $item}...{/foreach}

The functions are listed with their parameters in Template functions. The ones you use most:

Template operators

An operator takes parameters in brackets, in a fixed order, separated by commas. Most also take an input: the value before a pipe. The output of one operator can be piped into the next:

{$node.object.published|l10n( 'shortdate' )}
{$node.name|wash|shorten( 40 )}
{concat( 'To ', 'The ' )|prepend( 'Back ' )|append( 'Future' )}
{* Back To The Future *}

An operator can also be called without a pipe, with its input as the first parameter: {eq( $a, $b )} and {$a|eq( $b )} are the same test. Every operator, its parameters and an example: Template operators. Some you will use on almost every page:

Operator Does
wash escapes a value for HTML; see Template security
ezurl, ezimage, ezdesign, ezroot addresses of pages, images and design files; see URL handling
i18n a translated text: {'Search'|i18n( 'design/​standard/​layout' )}
l10n, datetime dates, times, numbers and prices for the current locale
fetch data from a module; see Information extraction
concat, append, prepend, shorten, upfirst, implode, explode strings and arrays
eq, ne, gt, lt, and, or, not, cond, first_set, is_set tests and choices
count, contains, array, hash, array_merge arrays

The difference between functions and operators, and why some things exist as both, is explained in Functions and operators of the template language manual.

Your own operators and functions

An extension adds operators and functions in PHP: a class with the operator's code, registered in the extension's autoloads/​eztemplateautoload.​php, with the extension named in site.ini [TemplateSettings] ExtensionAutoloadPath​[]. A PHP function that takes one value can be made an operator without code, with template.ini [PHP] PHPOperatorList​[<operator>]=<function>. Operators written this way also work in Smarty and Twig templates. See A custom template operator and Custom template functions.

In this section

Contributors

Comments (2 historical)

Written by readers of the earlier documentation sites, kept as they were.

  1. My own functions?

    Adrien ·

    Can I declare my own functions?

    1. Re: My own functions?

      Gaetano ·

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

Comments

Add a comment

Comments are read by a moderator before they appear.