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:

Tips and Tricks

A list of user-submitted tips ...

Technical Change History

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

Download WebDNA Applications

WebDNA applications...

AWS Raw WebDNA LAMP-Plus WebServer

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

WebDNA Libraries

A list of available libraries for WebDNA...


A compilation of some user's questions...

Related Readings:


Enable the WebDNA programmer to input XML data into a WebDNA variable...

Web Hosting Control Panels and WebDNA

Web Hosting Control Panels are becoming prevelant in the industry...


Capitalizes the first letter of all words in a sentence...


Embeds the results of an external function...


The formulas...


[math] calculates equations using numbers...