Skip to main content

Custom Dynamic Expressions

How to write custom dynamic expressions.

Sadhika Yamasani avatar
Written by Sadhika Yamasani
Updated over a month ago

Write dynamic expressions to create custom experiences tailored to your site and users.

Dynamic text will handle "number" and "string" and must always be declared when using a variable. E.g var<string> or var<number>.

The type used in the dynamic expression corresponds to the type the variable has been set up as in the site mapping. Variables used in dynamic expressions must already be mapped for your site.

Surface dynamic values

var<number>("product.price")

Concatenate static message and dynamic value

Use ++ to concatenate static message with a dynamic variable or expression.

"You have £" ++ var<number>("basket.value") ++ " worth of items in your basket. "

Form conditional expressions

If/else conditional expression

if var<number>("basket.value") < 20 then "Only £" ++ 20 - var<number>("basket.value") ++ " away from Free shipping"

else "You have qualified for Free shipping"

In this example we first set a condition (if the basket.value is less than 20), specify what message we want to surface in that case and then specify what message to surface if the condition is not met.

If/else if/else conditional expression


if var<number>("basket.number-of-items") < 1 then "Add 2 items to qualify for a free gift" else if var<number>("basket.number-of-items") == 1 then "Buy one more product to get a free gift" else "You have qualified for a free gift"

In this example the principle remains the same, the difference is we have added an additional condition. The logic proceeds to the else expression only if none of the other conditions is met.

There is no limit on how many else if conditions you can add as long as they logically make sense with each other.

Conditional Expressions with AND(&&) and OR(||)



if (var<number>("basket.value") > 20 && var<number>("basket.items") > 2) || (var<number>("basket.value") < 20 && var<number>("basket.items") > 4) then "You have qualified for the multisave discount" else ""

Form arithmetic expressions

You can perform basic arithmetic calculations - addition (+), subtraction (-), division (/) and multiplication (*)

var<number>("product.price") - (var<number>("product.price") * 0.10)

Limitations

  • Products of arithmetic calculations cannot be rounded up or down natively

  • Products of arithmetic calculations will be displayed up to the second digit after the decimal point

Did this answer your question?