Documentation / Tutorials / Quick Samples
Samples for Variable Scope (template, module, environment)
/ Quick Samples / Samples for Variable Scope (template, module, environment)
The scope of a variable is defined it’s range in the program under which it can be accessed. The scope of a variable is the portion of the program within which it is defined and can be accessed.”
AW has three types of variable scopes:
- Local scope – module
- Global scope – env
- Static scope – template
Set variable:
|
||
Get variable:
|
Template Scope:
Variable access is restricted within the template only, accessible within the template itself.
1 2 3 4 5 6 7 8 9 10 11 |
[templates.add main] //** Set variable in Template **// [template.set variable_text="I am template scope value" /] Variable Text in Main: [template.get variable_text /] [templates.run example /] [/templates.add] [templates.add example] //** NOT accessible here **// Variable Text in Example: [template.get variable_text /] [/templates.add] |
Module Scope:
Access the variable it self module also and in any template of that module, variable is accessible in all the templates of that module.
1 2 3 4 5 6 7 8 9 10 11 |
[templates.add main] //** Set variable in Module **// [module.set variable_text="I am module scope value" /] Variable Text in Main: [module.get variable_text /] [templates.run example /] [/templates.add] [templates.add example] //** Accessible here **// Variable Text in Example: [module.get variable_text /] [/templates.add] |
Environment Scope:
Initialize the variable and access anywhere wherever you need it. Within template or any other module or set it in the module and access in another service, everywhere it is accessible.
1 2 3 4 5 6 7 8 9 10 11 |
[templates.add main] //** Set variable in Environment **// [env.set variable_text="I am in global scope value" /] Variable Text in Main: [env.get variable_text /] [templates.run example /] [/templates.add] [templates.add example] //** Accessible here and in any other module or service... **// Variable Text in Example: [env.get variable_text /] [/templates.add] |
Access a value from one module to any other, use the env scope and access the value.
1 |
Variable Text in Example: [env.get variable_text /] |