Explicitly define a block of WebDNA code that has a separate variable space
numero = 235-Scope begin...[scope name=mytempvars][text]a=11[/text][text]b=22[/text][text]c=33[/text]List of local scope variables...Result...-Scope begin...List of local scope variables...a=11b=22c=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...
[listvariables scope=mytempvars][name]=[value][/listvariables]-Scope end...[/scope]List of variables outside scope...[listvariables scope=mytempvars][name]=[value][/listvariables]
[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=1local_2=2local_3=3local_4=4local_5=5local_6=6local_7=7local_8=8local_9=9local_10=10By default, text variables created within a function are discarded after thefunction has finished. If you want to create a text variable within afunction that persists after the function completes, then you need toexplicitly 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 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]
[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]
[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]
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!
...
WebDNA ModulesA list of the currently available modules...
WebDNA LibrariesA list of available libraries for WebDNA...
Tips and TricksA list of user-submitted tips ...
Technical Change HistoryThis Technical Change History provides a reverse chronological list of WebDNA changes...
F.A.QA compilation of some user's questions...
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 encryptionDatabase Automatic Encryption (from WebDNA 8...
[random]will display a random number...