Skip to main content

Advanced Uses in Workspaces

Key Concepts​

It is possible to define multiple workspaces that have their own associated objects. This allows flexible and powerful handling of variables.

Example​

The text to be parsed can belong to an object that can be bound to a workspace.

Suppose that we have the following structure

Object_1:
workspace = workspace_1
text = “Hi, my name is Davina. My email address is {{ email }}, my phone number is
{{ phone }}, my Skype id is {{ skype}} and my var 4: {{ this.var_4 | $”VAR_NOT_FOUND” }}“

Object_2:
workspace = workspace_2
text = “Hi, my name is Davina. My email address is {{ email }}, my phone number is
{{ phone }}, my Skype id is {{ skype}} and my var 4: {{ this.var_4 | global.var_4 | $”VAR_NOT_FOUND” }}“**

when parsing the above structure, the results should be

Object_1:
text = “Hi, my name is Davina. My email address is davina@apimetrics.com, my phone number is
+44-7123-456789 and my Skype id is davina@apimetrics.com and my var_4: VAR_NOT_FOUND”

Object_2:
text = “Hi, my name is Davina. My email address is davina@apimetrics.com, my phone number is
+44-7123-456789 and my Skype id is davina@apimetrics.com and my var_4 value_4”

Explanation​

Object_1 is bound to workspace_1

Object_2 is bound to workspace_2
Object 2 belongs to Object 1. Variables associated with Object 2 will be searched for
in the following workspaces: workspaces_2, workspace_1, global.

If the workspace of variable is not defined, the parser will search first in workspace_2. If the
variable is not defined in workspace_1, it will search in workspace_1. If the variable is not defined in workspace_1, it will search in the global workspace.

Object 1: variables associated with Object 2 will be searched for in the following workspaces: workspace_1, global.

This search order in workspaces defines the principle of workspace scopes.

To force the parser to search for a variable only in the current object workspace context, a special workspace reserved name this is used in the form this.var.

With this usage, the user can define the search order as shown in the above example for var_4. var_4 is not defined in Object_2. The alternative is global, and var_4 is defined in global. global workspace var_4 is returned. Because var_4 is not defined in Object_1, the alternative is text VAR_NOT_FOUND is returned.

Important

The global workspace is always the last workspace to be searched in for a variable.