ibexa

Caution: This documentation is for eZ Publish legacy, from version 3.x to 5.x.

def

Summary

Declares (and defines) a variable. Warns if the variable already exists.

Usage

{def $var1=value1 [ $var2=value2 [...] ]}

Parameters

NameTypeDescriptionRequired
$var1 string Name of variable number one (with a dollar sign in front of it). Yes.
value1 any The value that should be assigned to variable one. Yes.
$var2 string Name of variable number two (with a dollar sign in front of it). No.
value2 any The value that should be assigned to variable two. No.

Description

This function allows the declaration and definition of a single variable or a group of variables. The "undef" function can be used to flush/destroy variables that were created using the "def" function. Please note that this function does not support the "name" and the "scope" parameters (like the old {let} did).

Replacement for "default"

The following technique can be used as a replacement for the old "default" function:

{if is_set( $a )|not}
  {def $a=5}

Examples

Example 1

{def $oranges=13}

This example demonstrates how the "def" function can be used to declare a variable called "oranges". The variable will be declared as an integer with a value of 13.

Example 2

{def $oranges=13 $apples='There are no apples.'}

or

{def $oranges=13
     $apples='There are no apples.'}

These code snippets demonstrates how the "def" function can be used to declare multiple variables. A variable called "oranges" will be declared as an integer with a value of 13. A variable called "apples" will be declared as a string containing the following characters: "There are no apples.".

Balazs Halasy (28/02/2005 1:38 pm)

Balazs Halasy (03/10/2005 1:36 pm)


Comments

  • Replacement for "default" not correct

    The ending if tag is missing. So it should be like this:
    {if is_set( $a )|not}
      {def $a=5}
    {/if}
    

  • Schemers

    def seems to be similar to let* in Scheme. This means you can do things such as

    {def $a=1 $b=$a}

    and $b would get bound to 1 as well.