with

The $with function changes the value of the constant $input to the passed object (parameter host). This change is only valid within the transferred expression (parameter expression).
This is needed to change the data context for a partial expression without having to retrieve the same data again and again.

Syntax

$with(host,expression)

Parameter

Name

Description

host

The value which the constant $input should take for the execution of the passed expression.

expression

The path to a data field.
As always, path parts are separated by points (periods/fullstops). e.g. 'datenFeldLevel1.datenFeldLevel2'.
List entries can be accessed via the index (starting at 0) as a data field.
e.g. 'datenFeldDerListe.3' → accesses the fourth element of a list.

Return value

The return of the transferred expression (parameter expression).

Example

The following data of an element container with element id 5 is given:

Example host object in JSON format
{
"person": {
"name": "Robert Weber",
"age": "32",
"tasks": [
"IT lead",
"3rd Level Support",
"Software Customizing"
]
}
}

The object shown above can be read using the el (Read element data) function. As a result of the expression, both the name of the person and their primary task (first element of tasks) should be returned.

// Expression using $with
$with($get($el(5),person),{name} - {tasks[0]})
 
// Expression without $with - $el(5) has to be accessed over and over again
$get($el(5),person.name) - $get($el(5),person.tasks[0])

The result of the example for the object shown above is: 'Robert Weber – IT Manager'.

Special case for the parameter evaluation of $with

Parameters that are listed after the first one are combined to one expression. Thus, the following is also possible (see example above).

$with($get($el(5),person),{name}, {tasks[0]})

Results: 'Robert Weber, IT Manager'
The comma was included in the expression to be executed instead of evaluating a third parameter.