Technical References - [scope]

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

[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]
List of local scope variables...

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


List of variables outside scope...

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


-Scope begin...
List of local scope variables...
-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]
[listvariables scope=test_function][name]=[value]




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]

[return]anything you want displayed[/return]


[myfunction] produces [var1] and [var2]


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).


Top Articles:

WebDNA Libraries

A list of available libraries for WebDNA...

AWS Raw WebDNA LAMP-Plus WebServer

Amazon Web Services (AWS) README for Machine Image ID...


A compilation of some user's questions...

WebDNA Modules

A list of the currently available modules...

Technical Change History

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

Tips and Tricks

A list of user-submitted tips ...

Related Readings:


Loops through the enclosing text the specified number of times...


WebDNA provides a few options for password protecting your pages...


Displays a specific MIME header...


Displays the method...




calculates the CRC32 value of a given file...