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 Modules

A list of the currently available modules...

Download WebDNA Applications

WebDNA applications...

WebDNA reference

A list of all WebDNA instructions...


A compilation of some user's questions...

Tips and Tricks

A list of user-submitted tips ...

Technical Change History

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

Related Readings:


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


Displays information about a particular file or folder...


There is hardly a website that doesn't at some point need to send an email...


Extracts middle portion of the text between any two strings...


Removes HTML or WebDNA tags from a string of text...


Adds a product to the specified shopping cart...