IsDefined

Determine whether a given variable reference exists.

For example:

  • isDefined( "luis" ) will test for the existence of an lmajano variable in any accessible scope.

  • isDefined( "variables.foo" ) will test for the existence of a foo variable in the variables scope.

  • isDefined( "brad.age" ) will test for the existence of an age key in the brad struct, in any accessible scope

Method Signature

IsDefined(variable=[string])

Arguments

Argument
Type
Required
Description
Default

variable

string

true

The variable reference to test for existence. For security reasons, only dot-notation is supported. Struct/array bracket notation is not supported, nor is function invocation, etc.

Examples

Using IsDefined

Checking for the existence of a form variable.

<bx:if isDefined( "form.submit" ) >...</bx:if>

Scope Evaluation Order and Unscoped Variables

Beware of scope evaluation order when checking for an unscoped variable name.

Run Example

Result: Is 'foo' defined? YES (url.foo)

Dot-notation Variable Names

Potentially unexpected behavior when checking for a dot-notation variable containing a scope name.

Run Example

Result: Is 'form.submit' defined? YES (local['form.submit']) Is 'submit' defined? YES(form.submit)

Additional Examples

Run Example

Last updated

Was this helpful?