The TMLContext is the base object of the TMLScript runtime. It combines two purposes:
All methods of this object are case insensitive and can be used in any case variants, although we encourage you to use the case that is documented here.
The base TMLContext object of a script is reachable as "this" in all TMLScript code that does not belong to a TMLScript custom object (in which the "this" object is of course the TMLScript object itself). Specifying "this" is optional. You can also just use all methods and properties of the base TMLContext without "this." as if they were global functions and variables, if their names do not collide with other variables and functions.
The TMLContext object offers a shortcut syntax for direct access to items, WebTML variables and metadata fields of the current context document. This syntax lets you read those fields by just using their names as object properties. Specify the name in lowercase to read an item or WebTML variable, specify it in uppercase to read a metadata field. These are actually shortcuts to the methods this.item and this.meta of this object. See the examples how this is used.
You can also write to WebTML variables with this shortcut syntax when setting values to these "virtual" object properties. If there is an existing WebTML session variable of the property name it is updated. Otherwise this creates a new or updates an existing normal WebTML variable.
As "this" object in all scripts. The "this" qualifier is optional and can be omitted, so you may also directly use TMLContext methods and properties like global functions or fields.
|Allowed in script types||
|Properties and methods||
Reading an item "body" in three different ways. First in full syntax using the method "item". Then in shortcut syntax using the item name as object property in lowercase. Then even shorter, leaving out the optional "this" reference:
Using the full method "meta" you can also retrieve non-content metadata, like the database key in this example:
return this.meta("db", "dbkey");
Retrieving a different context. This is again a full TMLContext object which points to a different document, in that case the root document of the base TMLContext's document:
var rootContext = this.context("root");
Using the shortcut syntax to set WebTML variables: When you omit the "var" operator when setting a variable you effectively create or update a WebTML variable, which then can also be retrieved via <tml:item/>
If there is an existing WebTML session variable of the used name then this syntax updates it. Therefor the line "sessionvar++" effectively modifies the session variable set before: