def
Summary
Declares (and defines) a variable. Warns if the variable already exists.Usage
{def $var1=value1 [ $var2=value2 [...] ]}
Parameters
Name | Type | Description | Required |
---|---|---|---|
$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
Friday 16 May 2008 6:37:20 am
Dirk
Schemers
Thursday 30 October 2008 10:17:36 am
Miguel Pérez
{def $a=1 $b=$a}
and $b would get bound to 1 as well.