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.".

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2013 eZ Systems AS (except where otherwise noted). All rights reserved.