String operators
This page is for designers who shape text in templates. These operators come from eZTemplateStringOperator,
eZTemplateTextOperator and eZTemplateNl2BrOperator (lib/eztemplate/classes/). Since 6.0.13, about sixty PHP string
functions are operators as well (PHP string functions as operators).
Contents
Case
| Operator | Result for 'hello world' |
|---|---|
upcase | HELLO WORLD |
downcase | hello world |
upfirst | Hello world |
upword | Hello World |
Prefer CSS text-transform for purely visual case: screen readers and copy-paste keep the original text.
Length and trimming
$node.name|shorten( 60 ) {* at most 60 characters, '...' added when cut *}
$text|shorten( 120, '…' ) {* own ending *}
$text|trim {* spaces removed at both ends *}
$text|simplify {* runs of spaces reduced to one *}
$code|pad( 6, '0' ) {* str_pad: '42' becomes '420000' *}
$text|wrap( 72 ) {* wordwrap at 72 characters *}shorten defaults: length 80, sequence ..., cut on the right (from the operator's code). For rich text, shorten the
plain text: {$node.data_map.intro.content.output.output_text|strip_tags|shorten( 160 )|wash}.
Joining and layout
concat( $first, ' ', $last )
$text|nl2br {* line breaks to <br>: wash first *}
$text|break {* the same as nl2br in the string operator *}
'x'|indent( 4 ) {* indentation *}chr and ord convert between characters and codes.
Counting
$text|count_words
$text|count_chars {* multibyte aware: mb_strlen when available *}Escaping comes last
Shape first, then wash: {$text|shorten( 100 )|wash}. For nl2br, wash before it so the <br> survives:
{$text|wash|nl2br} (Wash and escaping).
Related pages
- PHP string functions as operators
- Wash and escaping
- Operator reference
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
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.