scope

[scope] explicitly defines a block of WebDNA code that has a separate variable space.
Meaning that variables defined within a [scope], only exist for the duration of WebDNA within that [scope] context.

[scope name=scopeTest]
[text]variable1=abc[/text]
The value of variable1 = [variable1]
[/scope]

The value of variable1 = [variable1]

The result of the above example will return:
The value of variable1 = abc
The value of variable1 = [variable1]
variable1 remains 'raw' because the text variable "variable1" is not available outside the scope.

Parameters

ParameterDescription
name(optional) The name assigned to the scope. This name can be used with the scope resolution operator to 'access' variables stored in the 'named' variables space but only for the duration of the scope context.
Example WebDNA code:
[scope name=mytempvars]
    [text]a=11[/text]
    [text]b=22[/text]
    [text]c=33[/text]

    Access the variables inside the scope:
    [listvariables scope=mytempvars][name]=[value]
    [/listvariables]
[/scope]

Access the variables outside the scope:
a = [a]
b = [b]
c = [c]

Access the variables outside the scope using the scope name:
[listvariables scope=mytempvars][name]=[value]
[/listvariables]

Results:
Access the variables inside the scope:
a=11
b=22
c=33

Access the variables outside the scope:
a = [a]
b = [b]
c = [c]

Access the variables outside the scope using the scope name:
a=11
b=22
c=33

The 'local' scope variables; 'a','b','c', only exist between the [scope] tags or when called using the scope name.

This is useful when you need to create several temporary variables for a specific block of WebDNA code, but do not want the variables 'cluttering' the global template variable space.

Scope and Functions:
WebDNA functions have their own implied scope. Meaning that when variables are created inside of a function definition, the variables are local to that function. The 'name' of the variable space in the function, is the function name itself.

Example WebDNA code:
[function name=test_function]
   [loop start=1&end=10]
      [text]local_[index]=[index][/text]
   [/loop]
   [listvariables scope=test_function][name]=[value]
   [/listvariables]
[/function]

[test_function]

Results:
local_1=1
local_2=2
local_3=3
local_4=4
local_5=5
local_6=6
local_7=7
local_8=8
local_9=9
local_10=10
By default, text variables created within a function are discarded after the function has finished.

Text Variables with Global Scope
A text variable with scope set to global will exist outside the function or scope.

Example WebDNA code:
[function name=myfunction]
   [text scope=global]var1=foo[/text]
   [text]var2=bar[/text]
   Anything entered here as text within the function will not display,
   if you want it to display on the rendered page then put it inside a [return] context:
   [return]This text will display on the rendered page:[/return]
[/function]

[myfunction] produces [var1] and [var2]

Result:
[myfunction] [var1] and [var2] will render as:
This text will display on the rendered page: foo and bar

Reserved Scope Names:
WebDNA has a number of 'reserved' scope names:
"global" : Refers to the 'normal/secure' template variable space.
"local" : When used inside of a function or scope context, refers to the variable space associated with the current function or scope.
"insecure" : Refers to the 'insecure' template variable space (this space also includes HTML form variables).