Caution: This documentation is for eZ Publish legacy, from version 3.x to 5.x.
For 5.x documentation covering Platform see eZ Documentation Center, for difference between legacy and Platform see 5.x Architecture overview.



Checks if an array contains a specific element.


input|contains( element )


element any The element that should be matched. Yes.


TRUE if the element is found, FALSE if not.


This operator checks if the input array contains a specific element (specified using the first parameter). If it does, the operator will return TRUE, otherwise FALSE will be returned.


Example 1

{array( 1, 2, 3, 4, 5 )|contains( 3 )}

Returns TRUE.

Example 2

{array( 1, array( 3, 4 ), 5 )|contains( array( 3, 4 ) )}

Returns TRUE.

Example 3

{array( 1, array( 3, 4 ), 5 )|contains( 3 )}

Returns FALSE.

Balazs Halasy (05/02/2004 9:30 am)

Balazs Halasy (04/05/2005 1:28 pm)


  • doesn't work when "element" is a node

    When using this function to see if an array contains a node, it always comes back false. It seems that "element" has to be a simpler datatype.
  • correctly inconsistent :-)

    As correctly documented here, the contains() operators does **not** work like this
    {if contains(array(1,2,3),3)}

    Instead, you have to write
    {if array(1,2,3)|contains(3)}

    (in 3.10)