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

eq

Summary

Returns TRUE if the input equals the first parameter or if all parameters are equal.

Usage

input|eq( value1 [, value2 ] )

Parameters

NameTypeDescriptionRequired
value1 any A variable/value that should be compared. Yes.
value2 any Another variable/value that should be copmared. No.

Returns

TRUE or FALSE (see below).

Description

This operator compares the contents of two or more variables and/or values. If the input parameter is used, the operator will compare it with the first parameter. If the provided variables/values match, the operator will return TRUE, otherwise FALSE will be returned. If more than one parameter is provided, the operator will compare all parameters. If all parameters are found to be equal, the operator will return TRUE, otherwise FALSE will be returned. If more than one parameter is provided, the operator will simply ignore the input parameter.

Note that "eq" compares the values in the same way as the '==' operator in PHP programming language (for example, 0.1 and 0.10 will be equal). Refer to the PHP reference documentation for more information. It is recommended to use the “compare” template operator for string comparision.

Examples

Example 1

{if 1|eq( 1 )}
    The truth is out there.
{else}
    The day the earth stood still.
{/if}

The following output will be produced: "The truth is out there".

Example 2

{if 1|eq( 2 )}
    The truth is out there.
{else}
    The day the earth stood still.
{/if}

The following output will be produced: "The day the earth stood still".

Example 3

{if eq( 1, 1 )}
    The truth is out there.
{else}
    The day the earth stood still.
{/if}

The following output will be produced: "The truth is out there".

Example 4

{if eq( 1, 2 )}
    The truth is out there.
{else}
    The day the earth stood still.
{/if}

The following output will be produced: "The day the earth stood still".

Example 5

{if 1|eq( 1, 1 )}
    The truth is out there.
{else}
    The day the earth stood still.
{/if}

The following output will be produced: "The truth is out there".

Example 6

{if 2|eq( 1, 1 )}
    The truth is out there.
{else}
    The day the earth stood still.
{/if}

The following output will be produced: "The truth is out there.".

Example 7

{if 1|eq( 1, 2 )}
    The truth is out there.
{else}
    The day the earth stood still.
{/if}

The following output will be produced: "The day the earth stood still".

Balazs Halasy (05/02/2004 10:39 am)

Geir Arne Waaler (31/05/2010 1:23 pm)

Balazs Halasy, Julia Shymova, Geir Arne Waaler


Comments

  • usage tip

    It would be more helpful if the "usage" indicated:
    input|eq( value1 [, value2 [,...] ] )
    or
    eq( value1 [, value2 [,...] ] )
    • Re: usage tip

      When using as: input|eq(value)
      it makes no sense to specify more than one value, they are ignored.
  • evaluates to ..

    is there a list somewhere of what equals what ?

    is an empty string equal to 0 or null or none ?
    is undefined defined ?

    what would be wise to use as a default for 'no value' ?

    • Re: evaluates to ..

      {''|eq(0)}
      


      returns

      1 (i.e. true...)
    • Re: evaluates to ..

      This follows the PHP conversion to boolean rules which you can read there: http://php.net/manual/en/language.types.boolean.php
    • Re: evaluates to ..

      Use NULL for 'no value', it's there for that. (PHP haven't the distinction between "undefined" and "defined but void")