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]
[text]a=11[/text]
[text]b"[/text]
[text]c3[/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"
c3
-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 Modules

A list of the currently available modules...

Download WebDNA Applications

WebDNA applications...

WebDNA reference

A list of all WebDNA instructions...

F.A.Q

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:

ODBC

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

[fileinfo]

Displays information about a particular file or folder...

[sendmail]

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

[middle]

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

[removehtml]

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

[addlineitem]

Adds a product to the specified shopping cart...