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.

if

Summary

Allows conditional control by the way of an IF-THEN-ELSE mechanism.

Usage

{if <condition>}
...
[ {elseif <condition>} ]
...
[ {else} ]
...
{/if}

Description

This construct allows for conditional execution of code fragments. It is one of the most important features of many programming languages. The eZ Publish implementation makes it possible to do conditional branching by the way of the following elements: IF, ELSE and ELSEIF. The ELSE and ELSEIF elements are optional.

Examples

Example 1

{if eq( $var, 128 )}
    Hello world <br />
{/if}

If $var equals 128, the following output will be produced: "Hello world". If it does not equal 128, no output will be produced.

Example 2

{if eq( $var, 128 )}
    Hello world <br />
{else}
    No world here, move along. <br />
{/if}

If $var equals 128, the following output will be produced: "Hello world". If it does not equal 128, the output will be "No world here, move along.".

Example 3

{if eq( $fruit, 'apples' )}
    Apple tree <br />
{elseif eq( $fruit, 'oranges' )}
    Orange juice <br />
{else}
    Banana split <br />
{/if}

If $fruit equals "apples", the output will be "Apple tree", if it equals "oranges" then the output will be "Orange juice" - otherwise the output will be "Banana split".

Balazs Halasy (22/02/2005 1:09 pm)

Balazs Halasy (28/04/2005 8:29 am)


Comments

  • What is the syntax ???

    What is the synatx, to write an "if"on one line (like the "?" in C) ?

    Thanks in adavnce,

    D
    • Re: What is the syntax ???

      There is no one line "if". "?:" is not a control structure like "if". "?:" is an operator, the ternary operator.
      The operator in ez you are looking for seems to be "cond".
      PHP:
      $var = $condition?$valueOn:$valueOff;
      Smarty:
      {def $var = cond($condition,$valueOn,true(),$valueOff)}