Array operators
This page is for designers who build lists and look things up in them. The operators come from
eZTemplateArrayOperator (lib/eztemplate/classes/eztemplatearrayoperator.php). Most also work on strings.
Contents
Building
def $sizes = array( 'small', 'medium', 'large' )
def $labels = hash( 'small', 'S', 'medium', 'M', 'large', 'L' )
set $sizes = $sizes|append( 'xlarge' )
set $sizes = $sizes|prepend( 'tiny' )
def $all = $sizes|merge( $more_sizes )append, prepend and merge return a new array; assign it with {set}.
Testing
| Expression | True when |
|---|---|
$list|contains( 'x' ) | the array (or string) contains the value |
$text|begins_with( 'http' ) | starts with |
$text|ends_with( '.pdf' ) | ends with |
$a|compare( $b ) | the two are equal |
$list|count | (a number) the number of items; 0 counts as false in {if} |
Taking parts
$list|extract( 2, 3 ) {* 3 items from position 2 *}
$list|extract_left( 3 ) {* the first 3 *}
$list|extract_right( 2 ) {* the last 2 *}
$list|reverse
$list|uniqueJoining and splitting
$tags|implode( ', ' ) {* array to string *}
$csv|explode( ',' ) {* string to array *}
$user.role_id_list|implode( ',' ) {* a common cache-block key *}Changing
$list|insert( 1, 'new' ) {* insert at position 1 *}
$list|remove( 0, 1 ) {* remove 1 item at position 0 *}
'-'|repeat( 10 ) {* '----------' *}
$numbers|array_sumOlder names
array_append, array_prepend and array_merge are marked deprecated in the autoload file; use append, prepend and
merge.
Related pages
- Foreach loops
- 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.