Technical References - [scope]

Explicitly define a block of WebDNA code that has a separate variable space

numero = 235
interpreted = N
texte = [scope name=...][/scope] Enables a WebDNA programmer to explicitly define a block of WebDNA code that has a separate variable space. Meaning that variables defined within the 'scope', only exist for the duration of WebDNA between the 'scope' tags. Optional Tag Parameters: name - User defined name for the local variable space. 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). Named Scope: Lets create a named variable space called 'mytempvars', and create a few text variables in the new scope. We use the following code...
-Scope begin...[scope name=mytempvars][text]a=11[/text][text]b=22[/text][text]c=33[/text]List of local scope variables...
[listvariables scope=mytempvars][name]=[value] [/listvariables] -Scope end... [/scope] List of variables outside scope... [listvariables scope=mytempvars][name]=[value] [/listvariables]
Result... -Scope begin... List of local scope variables... a=11 b=22 c=33 -Scope end... List of global variables outside scope... So you can see that the 'local' scope variables; 'a','b', 'c', only exist between the [scope] tags. 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 you create variables 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. For example...
[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. If you want to create a text variable within a function that persists after the function completes, then you need to explicitly set the variable scope to global. For example:
[function name=myfunction]put stuff in here and it won't show...[text scope=global]var1=foo[/text][text]var2=bar[/text][return]anything you want displayed[/return][/function][myfunction] produces [var1] and [var2]
Result... anything you want displayed produces foo and [var2] Reserved Scope Names

There are a few '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).

[scope name=...][/scope]

Enables a WebDNA programmer to explicitly define a block of WebDNA code that has a separate variable space. Meaning that variables defined within the 'scope', only exist for the duration of WebDNA between the 'scope' tags.

Optional Tag Parameters:
name - User defined name for the local variable space. 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).

Named Scope:

Lets create a named variable space called 'mytempvars', and create a few text variables in the new scope.

We use the following code...

-Scope begin...
[scope name=mytempvars]
[text]a=11[/text]
[text]b=22[/text]
[text]c=33[/text]
List of local scope variables...


[listvariables scope=mytempvars][name]=[value]
[/listvariables]
-Scope end...

[/scope]

List of variables outside scope...

[listvariables scope=mytempvars][name]=[value]
[/listvariables]

Result...

-Scope begin...
List of local scope variables...
a=11
b=22
c=33
-Scope end...
List of global variables outside scope...

So you can see that the 'local' scope variables; 'a','b', 'c', only exist between the [scope] tags.

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 you create variables 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.

For example...

[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. If you want to create a text variable within a
function that persists after the function completes, then you need to
explicitly set the variable scope to global. For example:

[function name=myfunction]

put stuff in here and it won't show...

[text scope=global]var1=foo[/text]
[text]var2=bar[/text]

[return]anything you want displayed[/return]

[/function]

[myfunction] produces [var1] and [var2]


Result...

anything you want displayed produces foo and [var2]



Reserved Scope Names

There are a few '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).


DOWNLOAD WEBDNA NOW!

Top Articles:

WebDNA reference

...

WebDNA Modules

A list of the currently available modules...

WebDNA Libraries

A list of available libraries for WebDNA...

Tips and Tricks

A list of user-submitted tips ...

Technical Change History

This Technical Change History provides a reverse chronological list of WebDNA changes...

F.A.Q

A compilation of some user's questions...

Related Readings:

ODBC

UNIX: Setting up WebDNA - ODBC - Database Server...

[xmlnodesattributes]

This context is used to iterate the attributes of a specific XML node...

[writefile]

[writefile] functions allows you to perform a wide variety of tasks...

[fileinfo]

Displays information about a particular file or folder...

DB encryption

Database Automatic Encryption (from WebDNA 8...

[random]

will display a random number...