OpenWGA 7.6 - OpenWGA Concepts and Features

Design and development » TMLScript » Items, metadata and variables in TMLScript

Setting WebTML variables

WebTML variables can also be set using TMLScript, which is - for normal variables - done via method this.setVar():

this.setVar("thevar", 1);


There is also a shortcut syntax here which sets the variable just as a property of the TMLContext object:

this.thevar = 1;


Qualifier "this" is also optional here, so setting a WebTML variable can also be done by simply setting a value to a yet undefined variable name:

thevar = 1;

Note the difference to the definition of a JavaScript variable:

var theScriptVar = 1;

This shortcut syntaxes can also be used to update existing WebTML variables of any type, like session and portlet variables.

To initially define session and portlet variables however other methods are used which to do not feature a shortcut syntax:

this.setSessionVar("theSessionVar", 1);

portlet.setVar("thePortletVar", 1);

portlet.setSessionVar("thePortletSessionVar", 1);

Scope of TML variables

Up to verion 7.1 of OpenWGA TML variables had global scope. Once defined those vars could be accessed from any TML.

Starting with OpenWGA 7.2 (that meens version compliance 7.2) TML variables have local scope. They can be accessed inside the TML where the var is definied but not outside this TML.

There is however a way to define globals vars as well. Global vars have to be definied using WGA.TMLPage.setVar(<name>,<value>). Such vars can either been accessed via WGA.TMLPage.getVar(<name>) or directly like any other var/item.