Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,059 of 9,059 pages
About the help in other languages
All help pages

Smarty templates: operator reference

This page is for template developers who write .stpl templates and need the exact form of one operator. It lists every template operator a standard installation registers, grouped by area, with its .stpl form, whether…

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/guides/smarty-templates-operator-reference.md

On this page

Smarty templates: operator reference

This page is for template developers who write .stpl templates and need the exact form of one operator. It lists every template operator a standard installation registers, grouped by area, with its .stpl form, whether it needs the prefix exp_, how it takes its input, and an example. The rules behind the columns are explained in Smarty templates: operators and fetch functions; read that first if the words "input" and "param" below are new to you.

The list was taken from the code: the operator registrations of lib/eztemplate/classes/eztemplateautoload.php, kernel/common/eztemplateautoload.php, kernel/private/eztemplate/eztemplateautoload.php, lib/ezpdf/classes/eztemplateautoload.php, [PHP] PHPOperatorList[] of settings/template.ini, and the autoloads/eztemplateautoload.php of the extensions shipped with the installation. The input mode of each operator is what expSmartyRenderer::operatorInputMode() decides from the operator's template hints, and for the operators without hints from expSmartyRenderer::PARAMETER_OPERATORS and [SmartySettings] ParameterOperatorList[] of smarty.ini.

How to read the tables

Name in .stpl. The name to write after the pipe or before the parentheses. exp_<name> where Smarty 5 has a modifier of the same name (Smarty's own modifiers always win; exp_ steps past them). An operator whose own name starts with exp_ (exp_path, exp_environment) is called by that name.

Mode.

  • input: the operator works on its input. $x|op:a:b passes $x as the input and a, b as parameters; op($x, a, b) is the same call. Called without an input (a .tpl op(a, b) with no pipe), write op(null, a, b). Every operator without template hints is of this kind, which includes nearly every operator of the extensions, except the kernel's operators that read their parameters only (below) and those an extension lists in [SmartySettings] ParameterOperatorList[] of smarty.ini.
  • param: the operator reads its parameters only. The piped value becomes the first parameter, so $a|op:b and op($a, b) are the same call, in any order you like to write it. The function form of the .tpl is the .stpl form: {ezhttp('SearchText', 'get')}, {if has_role('Editor')}. For the kernel's operators without template hints that are of this kind (ezhttp, has_role, topmenu ...), a null in front, as in ezhttp(null, 'SearchText', 'get'), the form converted templates had before, is left out, so both forms work.

Example. A .stpl line. Where the template engine's own tests (eZTemplateOperatorMatrixTest, checked against .stpl by tests/tests/lib/smarty/expSmartyOperatorParityTest.php) have the case, the output is given after →.

Literals first, since several operators of the .tpl are literals in Smarty:

.tpl.stpl
array(1, 2, 3)[1, 2, 3]
hash('a', 1, 'b', 2)['a' => 1, 'b' => 2]
true(), false()true, false
null (a bare word, which the .tpl reads as the text 'null')'null'; for a real null write null
an empty parameter: i18n('ctx',,hash(...))expvoid(): i18n:'ctx':expvoid():[...]

Arrays and lists (eZTemplateArrayOperator)

OperatorName in .stplModeExample
arrayliteral [...]input{$list = [1, 2, 3]}
hashliteral [k => v]input{$h = ['x' => 'y']}{$h.x} → y
appendappendinput{[1]|append:2:3|exp_implode:','} → 1,2,3
prependprependinput{[3]|prepend:1:2|exp_implode:','} → 1,2,3
mergemergeinput{(['a' => 1]|merge:['a' => 2])|expattr:'a'} → 2
array_append, array_prepend, array_mergethe sameinputdeprecated names of append, prepend, merge
containscontainsinput{if [1, 2]|contains:3}y{else}n{/if} → n; works on strings too
comparecompareinput{if [1, 2]|compare:[2, 1]}y{else}n{/if} → y (order ignored)
extractextractinput{'abcdef'|extract:3} → def; extract:offset:length
extract_leftextract_leftinput{[1, 2, 3]|extract_left:2|exp_implode:','} → 1,2
extract_rightextract_rightinput{[1, 2, 3]|extract_right:2|exp_implode:','} → 2,3
begins_withbegins_withinput{if [1, 2, 3]|begins_with:1:2}y{/if} → y
ends_withends_withinput{if [1, 2, 3]|ends_with:2:3}y{/if} → y
implodeexp_implodeinput{$keywords|exp_implode:', '}
explodeexp_explodeinput{'a,,b'|exp_explode:','|exp_count} → 3
repeatrepeatinput{[1, 2]|repeat:2|exp_implode:','} → 1,2,1,2
reversereverseinput{(['x', 'y']|reverse)|expattr:0} → y
insertinsertinput{'ad'|insert:1:'bc'} → abcd
removeremoveinput{'abcd'|remove:1:2} → ad (offset, length)
replaceexp_replaceinput{[1, 2, 3, 4]|exp_replace:1:2:8:9|exp_implode:','} → 1,8,9,4
uniqueuniqueinput{['a', 'b', 'a']|unique|exp_implode:','} → a,b
array_sumarray_suminput{[0.5, 1.5]|array_sum} → 2

Logic and comparison (eZTemplateLogicOperator, eZTemplateControlOperator)

OperatorName in .stplModeExample
eqeqparam{if eq(4, 4, 4)}y{/if} → y; {if $a|eq:'x'}
neneparam{if $block.values.tag|ne:''}
lt, gt, le, gethe sameparam{if 2|lt:3}y{/if} → y; {if $count|gt:0}
andandparam{and(1, 'a', 'last')} → last (the last value when all are true)
ororparam{or(0, '', 'x', 'y')} → x (the first true value)
notnotparam{if $x|not}, {if not($list)}
true, falseliterals true, falseparam{$flag = true}
nullnull (operator)input{if 'x'|null}y{else}n{/if} → n
choosechooseinput{0|choose:'a':'b'} → a; {2|choose:'a':'b':'c'} → c
condcondparam{cond($edit_language, 'yes', 'no')}; write it as a function (see the note below)
first_setfirst_setparam{first_set($redirect_uri, $redirect_url, '/')}; {first_set(0, 'b')} → 0

cond and first_set read their parameters only. Piped, the piped value becomes the first parameter: $a|first_set:'d' is "the first of $a, 'd' that is set", and $a|cond:'x':'y' uses $a as the condition. A .tpl $a|first_set('d') ignores $a and is always 'd'; the converter writes it as first_set('d') to keep that. Smarty's own ==, !=, &&, ||, ! and ?: work too, but eq compares as the .tpl does ({if eq(1, '1')} is true; several parameters must all be equal).

Types (eZTemplateTypeOperator)

All of them read their parameters: is_set($x) and $x|is_set are the same.

OperatorName in .stplModeExample
is_arrayexp_is_arrayparam{if exp_is_array($module_result.content_info)}
is_boolean, is_integer, is_float, is_numeric, is_string, is_object, is_nullthe sameparam{if is_float(1.5)}y{/if} → y
is_classis_classparamparameters as in the .tpl
is_set, is_unsetthe sameparam{if is_set($block.view_type)}; Smarty's isset() also works
get_typeget_typeparam{get_type(5)} → integer; {get_type(true)} → boolean[true]
get_classget_classparam{get_class($node)}

Arithmetic (eZTemplateArithmeticOperator)

OperatorName in .stplModeExample
sum, sub, mul, div, modthe sameparam{1|sum:2:3} → 6; {div(100, 5, 2)} → 10; {sub(mul(3, 4), div(10, 5))} → 10
inc, decthe sameparam{inc(9)} → 10
max, minthe sameparam{max(1.5, 2.5, 2)} → 2.5
abs, ceil, floor, int, floatthe sameparam{-2.5|abs} → 2.5; {floor(-1.5)} → -2
roundexp_roundparam{2.6|exp_round} → 3
romanromanparam{4|roman} → IV
randrandparam{rand(1, 6)}
countexp_countinput{$list|exp_count}; {exp_count(null, 'abc')} → 3 (a string counts its characters)

Smarty's +, -, *, / and % are fine for numbers too.

Strings (eZTemplateStringOperator, eZTemplateTextOperator, eZTemplateNl2BrOperator)

OperatorName in .stplModeExample
washwashinput{$node.name|wash}; wash:'email', wash:'javascript', wash:'pdf'; see Security and escaping
upcase, downcasethe sameinput{'äöü'|upcase} → ÄÖÜ
upfirst, upwordthe sameinput{$title|upfirst}
count_wordsexp_count_wordsinput{''|exp_count_words} → 0
count_charscount_charsinput{'äöü'|count_chars} → 3
trimtriminput{'xxaxx'|trim:'x'} → a
simplifysimplifyinput{'a--b---c'|simplify:'-'} → a-b-c
shortenshorteninput{'hello world'|shorten:7:'..'} → hello..; shorten:7:'...':'middle'
padpadinput{'ab'|pad:4} → ab
wrapwrapinput{$text|wrap:72}
breakbreakinput{$text|break} (line breaks as <br />)
chr, ordthe sameinput{[97]|chr} → a; {'AB'|ord|exp_implode:','} → 65,66
concatconcatparam{concat(1, 2, 3)} → 123; {'a'|concat:'b'} → ab
indentexp_indentinput{'x'|exp_indent:3:'custom':'-'} → ---x
nl2brexp_nl2brinput{$text|wash|exp_nl2br}

indent and nl2br hint that their input is a parameter, but read it as their input when they run; the bridge lists them in expSmartyRenderer::INPUT_AT_RUN_TIME.

PHP string functions (eZTemplateStringsOperator)

Sixty-one PHP string functions are operators (PHP string functions as template operators). All are input operators: the piped value is the PHP function's subject.

Name in .stplOperators
with exp_exp_strip_tags, exp_strlen, exp_substr, exp_number_format
as they areaddslashes, addcslashes, bin2hex, hex2bin, chunk_split, convert_uudecode, convert_uuencode, hebrev, html_entity_decode, htmlentities, htmlspecialchars_decode, lcfirst, levenshtein, ltrim, rtrim, metaphone, quoted_printable_decode, quoted_printable_encode, quotemeta, similar_text, soundex, sprintf, vsprintf, str_contains, str_ends_with, str_starts_with, str_getcsv, str_shuffle, str_split, str_word_count, strcasecmp, strcmp, strcoll, strcspn, stripcslashes, stripslashes, stripos, stristr, strnatcasecmp, strnatcmp, strncasecmp, strncmp, strpbrk, strpos, strrchr, strripos, strrpos, strspn, strstr, strtok, strtr, substr_compare, substr_count, substr_replace, ristring, rstring
{$text|exp_substr:0:5}
{if $text|str_contains:'Expo'}...{/if}
{'%s has %d items'|sprintf:$name:$count}
{1234567.891|exp_number_format:2:'.':','}
{$node.data_map.success_text.data_text|exp_strip_tags}
{(first_set($form.parent.parent.vars, $form.parent.vars))|expattr:'name'|ristring:'_':'-'}

Smarty's own substr, strlen, strip_tags and number_format are PHP's functions with the same order of parameters, so the unprefixed names usually print the same; the prefixed names are what the converter writes and what is guaranteed to behave as in the .tpl.

Digests and units (eZTemplateDigestOperator, eZTemplateUnitOperator)

OperatorName in .stplModeExample
md5, crc32, rot13the sameinput{$module_result.content|md5}; {'a1z'|rot13} → n1m
sisiinput{1048576|si:'byte'} → 1.00 MB

Dates and locale (eZTemplateLocaleOperator)

OperatorName in .stplModeExample
l10nl10ninput{$node.object.published|l10n:'shortdate'}; types time, shorttime, date, shortdate, datetime, shortdatetime, currency, clean_currency, number
localelocaleinput{(((ezini('RegionalSettings', 'Locale'))|locale)|expattr:'http_locale_code')|wash}
datetimedatetimeinput{$time|datetime:'custom':'%d.%m.%Y'}
currentdatecurrentdateparam{currentdate()}
maketime, makedatethe sameinputwithout an input: maketime(null, hour, minute, second, month, day, year), makedate(null, month, day, year)
gettimegettimeinput{($time|gettime)|expattr:'year'}

Fetching and attributes (eZTemplateExecuteOperator, eZTemplateAttributeOperator)

OperatorName in .stplModeExample
fetchfetchparam{$children = fetch('content', 'list', ['parent_node_id' => $node.node_id, 'limit' => 10])}
fetch_aliasfetch_aliasparam{$children = fetch_alias('children', ['parent_node_id' => $node.node_id])}
attributeattributeinput{$node|attribute:'show'}: a table of the object's attributes, for debugging
dumpdumpinput{$node|dump}

More on fetch(): Fetch functions.

Images (eZTemplateImageOperator)

OperatorName in .stplModeExample
texttoimagetexttoimageinputparameters as in the .tpl
image, imagefilethe sameparamparameters as in the .tpl

An extension that registers an operator of the same name replaces the kernel's: in a siteaccess with sevenx_themes_media, image is the theme's operator (an input operator, written image(null, ...)).

Roles and policies (eZTemplateRoleOperator)

OperatorName in .stplModeExample
has_role, has_role_idthe sameparam{if has_role('Editor')}; {if has_role_id(5, $user_id)}
has_any_rolehas_any_roleparam{if has_any_role(['Administrator', 'Publisher'])}
has_role_by_user, has_role_by_user_idthe sameparam{if has_role_by_user($user, 5)}, parameters as in the .tpl
has_policy, has_policy_by_userthe sameparam{if has_policy('content', 'edit')}

They read their parameters only (the current user is the default): write them as in the .tpl. A value piped into them becomes the first parameter, so $current_user|has_role:'Editor' asks for a role named after the user; write has_role('Editor'). Details: Role and policy checks in templates.

Extensions, installation and environment (lib and kernel)

OperatorName in .stplModeExample
expinfoexpinfoparam{if expinfo('explayouts_ui')}...{/if}
installation_name, is_production_systemthe sameparam{installation_name()}; {installation_name(true)} (empty on a production system)
exp_environment, exp_environment_badgethe same (own exp_ names)param{exp_environment()}
exp_demo_modeexp_demo_modeparam{if exp_demo_mode()}...{/if}
audit_labelaudit_labelinputparameters as in the .tpl
csp_noncecsp_nonceparam<script nonce="{csp_nonce()}">...</script>; never inside {expcacheblock} (Security and escaping)
view_parameterview_parameterinput{$value|view_parameter}: a value encoded for /(name)/<value>
transfer_tools, transfer_actions, transfer_related, transfer_toolthe sameparamparameters as in the .tpl
ezpackageezpackageinputparameters as in the .tpl
ezmoduleezmoduleparam{if ezmodule('content/edit')}
module_paramsmodule_paramsparam{module_params()}
ezpreferenceezpreferenceparam{ezpreference('admin_left_size')}

URLs, settings and the request (eZURLOperator, eZi18nOperator)

OperatorName in .stplModeExample
ezurlezurlinput<a href={$node.url_alias|ezurl}>; {'/content/view'|ezurl:'no'}; {'/content/view'|ezurl:'no':'full'}
ezrootezrootinput<img src={$image.url|ezroot} />
ezdesignezdesigninput<link rel="stylesheet" href={'stylesheets/site.css'|ezdesign} />
ezimageezimageinput<img src={'logo.png'|ezimage} />
exturlexturlinputparameters as in the .tpl
ezsysezsysinput{'indexfile'|ezsys}
ezinieziniparam{ezini('SiteSettings', 'SiteName')}; {ezini('SiteInfo', 'CookiePolicyID', 'menu.ini')}
ezini_hasvariableezini_hasvariableparam{if ezini_hasvariable('SiteInfo', 'CookiePolicyID', 'menu.ini')}
ezhttpezhttpparam{ezhttp('SearchText', 'get')} (see the note)
ezhttp_hasvariableezhttp_hasvariableparam{if ezhttp_hasvariable('SearchText', 'get')}
i18ni18ninput{'Read more'|i18n:'design/standard/node'}; {'Order %id'|i18n:'design/shop':expvoid():(['%id' => $order.order_nr])}
d18nd18ninputas i18n, for a dynamic text
x18nx18ninput{'Text'|x18n:'myext':'design/myext'} (extension, context, comment, arguments)

ezhttp and ezhttp_hasvariable take the name and the type (post, get, session, cookie) as their parameters. They have no template hints; the bridge knows them as operators that read their parameters only (expSmartyRenderer::PARAMETER_OPERATORS), so the function form of the .tpl works: {ezhttp('SearchText', 'get')}. 'SearchText'|ezhttp:'get' is the same call, and ezhttp(null, 'SearchText', 'get'), which converted templates wrote before, still works. Wash what it returns: {ezhttp('SearchText', 'get')|wash}.

ezurl, ezroot, ezdesign and ezimage print the address in double quotes by default (href={...|ezurl}); :'no' leaves the quotes out, :'single' uses single quotes. With ezurlmultisite active, its own operators take over these ten names with the same forms.

Content, menus and text (kernel/common)

None of these has template hints. The input ones work on the value piped into them; as a function without an input, write null first, with the parameters of the .tpl. The param ones read their parameters only (expSmartyRenderer::PARAMETER_OPERATORS): write them as in the .tpl.

OperatorName in .stplModeExample
autolinkautolinkinput{$text|wash|autolink}
simpletagssimpletagsinput{$text|simpletags}
wordtoimagewordtoimageinput{$text|wordtoimage}
mimetype_icon, class_icon, classgroup_icon, action_icon, icon, flag_iconthe sameinput{$node.class_identifier|class_icon:'small'}; {$language.locale|flag_icon}
icon_infoicon_infoparam{icon_info('mimetype')}
alphabetalphabetparam{alphabet()}
month_overviewmonth_overviewinput{$events|month_overview:'published':$date}
treemenutreemenuparamtreemenu($module_result.path, $node_id, ['folder'], 0, 5), parameters as in the .tpl
content_structure_treecontent_structure_treeparamcontent_structure_tree(2, ['folder'], 2), parameters as in the .tpl
topmenutopmenuparam{topmenu('content')}
eztoceztocparam{eztoc($node.data_map.body)}
siteaccess_urlsiteaccess_urlparamparameters as in the .tpl
siteaccess_menu, siteaccess_menu_keythe sameparamparameters as in the .tpl
language_switcherlanguage_switcherparam{language_switcher($uri)}
pdf (lib/ezpdf)pdfparam{pdf('new_line')}, parameters as in the .tpl

siteaccess_url, siteaccess_menu and siteaccess_menu_key say they take no input ('input' => false), so they are param operators: siteaccess_url(a, b) and a|siteaccess_url:b are the same.

PHP functions of template.ini

[PHP] PHPOperatorList[] of settings/template.ini makes PHP functions operators: urlencode, urldecode, rawurlencode and rawurldecode in a standard installation. They are param operators with one parameter:

<a href="/search?q={$text|rawurlencode}">...</a>

Operators of the shipped extensions

Operators registered by an extension's autoloads/eztemplateautoload.php exist only in a siteaccess where the extension is active. Of the extensions shipped with the installation, only ezurlmultisite gives its operators template hints (the same as the kernel's URL operators); every other extension operator is an input operator: $x|op:a passes $x as its input, and a .tpl call without a pipe is written op(null, ...) in a .stpl. An extension makes an operator without hints that reads its parameters only a param operator with [SmartySettings] ParameterOperatorList[] in its smarty.ini.append.php (see Writing operators and functions).

ExtensionOperators
ezjscoreezscript, ezscript_require, ezscript_load, ezscriptfiles, ezcss, ezcss_require, ezcss_load, ezcssfiles, json_encode (write exp_json_encode: Smarty has json_encode), xml_encode, node_encode, has_access_to_limitation
eztagseztags_parent_string, latest_tags, user_limitations, tag_icon, eztagscloud
explayoutsexpl_parse, expl_strip, expl_has, expl_first, explayouts_safe_url, explayouts_safe_embed_url, explayouts_safe_color, explayouts_safe_tag, explayouts_safe_template_name, explayouts_safe_css_class
explayouts_uiexplayouts_ui_has_template
ezoeezoe_ini_section
ezfindsolr_escape, solr_quotes_escape
ezwebin, ezdemoezkeywordlist, ezarchive, eztagcloud, ezpagedata, ezpagedata_set, ezpagedata_append
ezurlmultisitethe ten URL operators above, and ezurl_path, ezurl_siteaccess, ezurl_roots
ezstarratingfetch_starrating_data, fetch_starrating_stats, fetch_by_starrating
xrowmetadatametadata, xrowmetadata_license, xrowmetadata_license_enabled, xrowmetadata_license_choices, xrowmetadata_license_info, xrowmetadata_license_inherited, xrowmetadata_license_class_settings
expaiexpai_money, expai_tokens, expai_number, expai_json, expai_retention, expai_help_url
expuiexp_config (own exp_ name)
cjw_newslettercjw_newsletter_preg_replace, cjw_newsletter_str_replace, cjw_newsletter_variable, cjwnl_condition_open, cjwnl_condition_else, cjwnl_condition_close, cjwnl_plaintext, cjwnl_richtext, cjwnl_interests_block, cjwnl_abs_url, cjwnl_text_underline, cjwnl_text_wrap, cjwnl_rendering_data
ezflowunserialize, json, feedreader, red5list, pagelink
ezwtezcreateclasslistgroups
enhancedezbinaryfileparsexml
bcwebsitestatisticsbc_ga_urchin, bc_ga_urchinOrder, bc_ga_xmlAttributeValue, bc_ga_jsEscapedString, bc_ga_formatNumericDecimal, bc_ga_script_url
str_replaceezstr_replace
owsimpleoperatorexample_sum
sevenx_themes_mediaabsolute_url, app, asset, component_content, content_link, content_tags, controller, embed_image, enhanced_link, exp_can_login_to_siteaccess, exp_path, exp_url, explayouts_render_result, explayouts_render_zone, exponential, fieldRelation, fieldRelations, fieldValue, filterChildren, filterFieldRelationLocations, filterFieldRelations, firstNonEmptyField, getParameter, get_netgen_open_graph, hasField, hasParameter, haveToPaginate, image, image_link, intro, item_content_link, item_image_link, item_params, item_view_template, json_ld, layout_title, ng_image_alias, ng_query, ng_render_field, ng_view_content, ngsite, ngsite_group_fields, ngsite_language_name, ngsite_topic_path, pagerfanta, parameter, parent, path, player, player_slide, poster, poster_slide, recipe_schema, redirect_to_site_root, render, render_esi, saveXML, site_url, siteaccess_href, tag_url, title, tpl_block_template, trans, video_thumbnail, youtube_id, and the deprecated aliases ibexa, ibexa_path, ibexa_url, nglayouts_render_result, nglayouts_render_zone

Real lines from the media port, all input operators called without an input:

<h3 class="title"><a href="{exp_path(null, $location)}">{ng_render_field(null, $content.fields.title)}</a></h3>
<article {item_params(null, $toolbar_macros, $content, $location)} class="view-type view-type-{$view_type}">
{$__loop1 = fieldRelations(null, $content, 'authors')}

An operator name that starts with exp_ and is registered (exp_path, exp_url, exp_config, exp_can_login_to_siteaccess, exp_environment ...) is that operator. Only a name that is not registered has its prefix removed: exp_count is count, exp_implode is implode. So exp_path can never stand for an operator named path; write path for that one.

Bridge helpers (not operators)

expattr, expvar, expvoid, expslice, expsectionloop, exprange, expsequence, expcolumn are modifiers of the bridge itself; see The helpers of the bridge.

Finding the operators of your installation

The tables cover what ships with the installation. Your own extensions add operators the same way: look for operator_names in extension/*/autoloads/eztemplateautoload.php of the extensions active in the siteaccess. To find out the mode of an operator, look for operatorTemplateHints() in its class: none, or 'input-as-parameter' => 'always', means input; 'input-as-parameter' => true or 'input' => false means param. Writing an operator that works in both engines: Writing operators and functions for .stpl.

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x