ON THIS PAGE
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Operators

Operators are essential building blocks in Dynamic Expressions, allowing you to perform calculations, comparisons, and logical evaluations. These symbols enable your workspace to process data, make decisions, and create interactive content.

Arithmetic Operators

Perform basic mathematical operations.

  • + (Addition): Adds two numbers or concatenates text strings.
    • Example: {{ 2 + 3 }} → 5
    • Example: {{ "Hello, " + sessionUser.name }} → Hello, John
  • - (Subtraction): Subtracts one number from another.
    • Example: {{ 10 - 4 }} → 6
  • * (Multiplication): Multiplies two numbers.
    • Example: {{ 5 * 3 }} → 15
  • / (Division): Divides one number by another.
    • Example: {{ 10 / 2 }} → 5
    • Note: Division by zero will return an error.
  • % (Remainder): Returns the remainder of a division.
    • Example: {{ 10 % 3 }} → 1
  • ** (Exponentiation): Raises a number to the power of another.
    • Example: {{ 2 ** 3 }} → 8

Comparison Operators

Used to compare values and return true or false.

  • == (Equality): Checks if two values are equal.
    • Example: {{ 2 + 2 == 4 }} → true
  • != (Inequality): Checks if two values are not equal.
    • Example: {{ sessionUser.stats.ideas != 0 }} → true
  • > (Greater than): Checks if the left value is greater than the right.
    • Example: {{ sessionUser.stats.likes > 10 }} → true
  • >= (Greater than or equal to): Checks if the left value is greater than or equal to the right.
    • Example: {{ 5 >= 5 }} → true
  • < (Less than): Checks if the left value is less than the right.
    • Example: {{ 3 < 10 }} → true
  • <= (Less than or equal to): Checks if the left value is less than or equal to the right.
    • Example: {{ sessionUser.stats.ideas <= 20 }} → true

Logical Operators

Used to combine multiple conditions.

  • && (AND): Returns true if both conditions are true.
    • Example: {{ sessionUser.stats.likes > 10 && sessionUser.stats.ideas > 5 }} → true if both conditions are met.
  • || (OR): Returns true if at least one condition is true.
    • Example: {{ sessionUser.rank == 3000 || sessionUser.rank == 5000 }} → true if the user is an Admin or Owner.
  • ! (NOT): Reverses the truth value of a condition.
    • Example: {{ !(2 + 2 == 5) }} → true

Conditional Operator

Sometimes you may want to execute conditional branches of your formulas, depending on contextual data. For example, you may want to:

  • Use different translation keys in your idea collection description depending on the rank of the current user.
  • Set different values on an idea in an automation action depending on whether or not it has more than a specified amount of e.g. comments.

You can use the conditional operator inside your dynamic expressions to accomplish these things. The conditional operator is special in that it accepts three operands.

It has the following structure: <condition> ? <when-true> : <when-false>

Here is a simple example: {{ sessionUser.stats.likes > 10 ? "Top-contributor" : "Rookie" }}

You can put anything inside the two branches of the conditional operator, including custom translation variables, or complex nested formulas.

For example, you may want to use different custom translation variables, depending on the rank of the current user:

{{ sessionUser.rank >= 3000 ? (sessionUser.stats.ideas > 20 ? "Super Admin" : "Admin") : "Member" }}

Grouping Operators

Used to control the order of operations by grouping expressions with parentheses ().

  • Example: {{ (2 + 3) * 4 }} → 20
  • Without parentheses: {{ 2 + 3 * 4 }} → 14
  • Note: Multiplication takes precedence.

Error Handling Tips for Operators

  • Avoid Division by Zero: To avoid errors when dividing by a variable that could be zero, use fallback logic with functions like MAX() or conditionals.
    • Example: Instead of {{ 10 / variable }}, use:{{ 10 / MAX(variable, 1) }} — ensures the divisor is at least 1.
    • Example using a conditional: {{ variable != 0 ? 10 / variable : "Undefined (Division by zero)" }} — shows a fallback message when the divisor is zero.
  • Check your parentheses: Ensure that you close all opening parentheses.
  • Use logical operators carefully: Double-check conditions to avoid unexpected results.

By mastering operators, you can create more complex and engaging Dynamic Expressions, enabling your workspace to respond intelligently to data and user interactions.

How helpful was this article?
Thank you! Your feedback helps us improve.
Oops! Something went wrong while submitting the form.