OpenWGA 7.0 - TMLScript reference

TMLContext "this"
Method :

context(contextExpression [, returnContextOnError])

On object TMLContext "this"
Usage Creates a TMLContext object for a different content document
Description Variant 1 with parameter contextExpression:

This method offers the same functionality as the WebTML attribute context. It received a context expression, retrieves the content document that is addressed by it and returns a TMLContext object that has this document in context.

If a context change fails this method normally returns the original TMLContext object again. You can retrieve a message about the cause of failure from property this.lastError. You can instead let this method return null if you set optional parameter "returnContextOnError" to false.

Variant 2 with parameter content:

This variant takes a content document in form of the WGAPI object "WGAContent" and constructs a TMLContext object that has it in context.
Parameters contextExpression (String):
Variant 1:  An OpenWGA context expression. Syntax is identical to that of WebTML attribute context

returnContextOnError (Boolean, optional):
Variant 1: Determines if on context change error the original context is to be returned, defaulting to true. If false this method returns null on a failed context change.

content (WGAPI object WGContent):
Variant 2: A WGAPi content object
Return value A TMLContext that matches the content that was addressed in the context expression. If context change fails returns either the original TMLContext or null if parameter "returnContextOnError" in Variant 1 was set to false.
Allowed in script types
  • WebTML pages and normal WebTML actions
  • Master actions
  • TMLScript tasks in jobs
  • Content type events
Examples Retrieving a TMLContext for my current parent document and retrieving it's title:

this.context( "parent" ).meta("title")

You can also use shortcut syntax on those returned TMLContext objects. So the following is equal:

this.context( "parent" ).TITLE

Using parameter "returnContextOnError" to be able to react on failing context changes:

var targetContext = context("name:home", false);
if (targetContext == null) {
    // Context change did not work. Set an error variable for display and cancel the script
    setvar("errormsg", "There is no document named 'home' !");

// The following script may assume the context change worked.