if/else

Executes a block of code only if a certain condition is true. elsif and else add more conditions within an if block.

Input
  • user.name = 'John Doe'
    {% if user.name == 'John Smith' %}Hello John Smith{% elsif user.name == 'Jane Smith' %}Hello Jane Smith{% else %}Hello stranger{% endif %}
Output
  • Hello stranger
and logical operator

In an if statement, use the and logical operator to return only if all operands return true

Input
  • user.name = 'John Smith'
    user.birthday = '01/01/80'
    {% if user.name == 'John Smith' and user.birthday == '01/01/80' %}Hello John Smith{% else %}ERROR: Wrong John Smith{% endif %}
Output
  • Hello John Smith
or logical operator

In an if statement, use the or logical operator to return if one of the operands return true

Input
  • user.name = 'John Smith'
    user.birthday = '01/01/80'
    {% if user.name == 'John Smith' or user.birthday == '12/12/80' %}Hello John Smith or person born on 12/12/80{% else %}ERROR: Wrong John Smith or not born in 12/12/80{% endif %}
Output
  • Hello John Smith or person born on 12/12/80