first_set
Summary
Returns the first parameter that is set (or FALSE).
Usage
first_set( value1 [, value2 [, ... ] ] )
Parameters
| Name | Type | Description | Required |
|---|---|---|---|
| value1 | any | A variable/value that should be evaluated. | Yes. |
| value2 | any | Another variable/value that should be evaluated. | No. |
Returns
The first value that is set or FALSE.
Description
This operator evaluates all parameters until one of them is found to be set. The parameter that is found to be set will be returned. If none of the parameters are set, the operator will return FALSE.
Examples
Example 1
{if first_set( $a, $b, $c )}
The truth is out there.
{else}
The day the earth stood still.
{/if}As long as $a, $b and $c are undeclared/unset, the following output will be produced: "The day the earth stood still".
Example 2
{first_set( $a, 256, $b )}As long as $a is undeclared/unset, the following output will be produced: "256".
Contributors
- Balazs Halasy Updated
- Massimiliano Bariola Commenter
Comments (1 historical)
Written by readers of the earlier documentation sites, kept as they were.
This code will give you unexpected results
Massimiliano Bariola ·
This code:
{def $myvar = first_set($myobject.contentobject.data_map.my_integer_var.data_int, 0)} MYVAR = {$idanag}; {$myobject.contentobject.data_map.my_integer_var.data_int}will display
MYVAR = ; 0
instead of
MYVAR = 0; 0
so, first_set handles 0s as "unset". this either needs to be documented or marked as a bug.