Expression Language is created based on Symfony Expression Language. It is working based on Dynamic Data. The purpose of the Expression Language is to allow users to use expressions for data accessing, data modification, data evaluation:
If for example there is a such dynamic data:
postData.queried_post.post_titlewill return "Our Products"
postData.queried_post.products.titlewill return "Pear"
upper(postData.queried_post.post_title)will return "OUR PRODUCTS"
"Price of " ~ postData.queried_post.products.title ~ " is " ~ postData.queried_post.products.price ~ "$"will return "Price of Pear is 0.48$"
postData.queried_post.products.price > 1will return "false"
postData.queried_post.products.price > 1 ? "Expensive Product" : "Cheap Product"will return "Cheap Product"
For the full list of available operators, please, refer to the official Expression Language syntax page Here we list the most using operators:
<=(less than or equal to)
>=(greater than or equal to)
not in(does not contain)
foo ? 'yes' : 'no'
We have created many useful functions to be used in expressions. They help to achieve some conditional logic or transform the data.
We can use both the final values and data variables (defined before the data variable with expression) to
pass the data inside the functions. Later there will be examples with
context given. Context is equivalent
of dynamic data in the builder. Context is the object of data variable names and their evaluated values.
We can pass both the final value as well as data variable names as arguments for functions!
How to use
Below is the usage example of a data variable type 'expression':
booksis a regular JSON value; in this example we modify each item - book - by adding key
addPricesis a variable type 'expression';
- the expression editor - the place where we wriote our expression
- the preview - the result of the expression
Remembering about the flow of data variables, we have used the previously declared variable inside the expression of
addPrices variable. In this case the value of
books variable was available in the context for 'foreach' function that is used inside the expression.
In this example we also use "closure" function. Its syntax is very similar to arrow functions in JS, we just use "dash" instead of "equal" sign for making the "arrow":
->. As any other function, this one also has arguments. The first one is an iteration item from our example, it is available with
o variable. The second argument is optional and it would be an index of the item.