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

Array operators

Building and working with arrays and hashes in templates: array, hash, append, prepend, merge, contains, extract, extract_left, extract_right, implode, explode, reverse, unique, insert, remove, repeat, begins_with…

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/designers/templates/array-operators.md

On this page

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

  1. Building
  2. Testing
  3. Taking parts
  4. Joining and splitting
  5. Changing
  6. Older names

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

ExpressionTrue 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|unique}

Joining 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_sum}

Older names

array_append, array_prepend and array_merge are marked deprecated in the autoload file; use append, prepend and merge.

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