Conditions

We need conditions to show a variable or text depending on certain conditions.

Comparing a Variable with a Value or Another Variable

Let's imagine that we have variable "gender", in which we will write "male" or "female" through a fork, depending on what the client wrote to the bot.
Now we need to send different texts to clients depending on their gender.
We can use Block Helper eq for comparing variables:
Привет!
{{#eq gender "женщина"}}
Хорошо, что ты написала!
{{/eq}}
{{#eq gender "мужчина"}}
Хорошо, что ты написал!
{{/eq}}
What's happening here?
We opened block helper #eq and used variable "gender" and string "female" with it.
The example shows that we can use so-called literals instead of variables, i.e. we can compare not only variables, but also strings and numbers at once.
Strings should be written in double program quotes ".
And after the body, we closed the block /eq. You should always close block helpers, otherwise an error will occur in the template, and the bot will not send anything.
A lot of block helpers that are used for comparisons have a so-called alternative block.
Let's look at our example again. There are only two options: we can only have male or female.
We may not make a separate block for each option but use a special separator {{else}}:
Привет!
{{#eq gender "женщина"}}
Хорошо, что ты написала!
{{else}}
Хорошо, что ты написал!
{{/eq}}
If string "woman" is written in variable "gender", the bot will write: Hello, madam. Thank you for writing to us., and in all other cases it'll say: Hello, sir. Thank you for writing to us.

Comparison "Less" or "Greater"

To compare two numbers and determine which number is greater, and which one is less, there are two block helpers #lt and #gt, respectively.
lt - less than
gt - greater than
Imagine that we ask the client how old he is in the bot, and add another variable in which we write "age".
Let's say we want to warn that only a client over 16 years old can use the bot. If the client is younger, we will ask him not to use the bot.
{{#lt age 16}}
К сожалению, ботом нельзя пользоваться до 16 лет
{{/lt}}
You can do the same with helper #gt and separator {{else}}:
{{#gt age 15}}
{{else}}
К сожалению, ботом нельзя пользоваться до 16 лет
{{/gt}}
It seems a bit illogical because we need those who are 16 years old and older, and we got those who are strictly greater than 16.
In order to include 16 in such cases, there are additional helpers #lte (less than or equal to) and #gte (greater than or equal to).
Let's change the last example to #gte and add a greeting for target customers:
{{#gte age 16}}
Ого! Добро пожаловать, вам так много лет!
{{else}}
К сожалению, вам еще нет 16 лет
{{/gte}}
By the way, block helpers can be nested inside each other. Let's combine two examples:
{{#gte age 16}}
Ого! Добро пожаловать!
{{#eq gender "женщина"}}Вы такая взрослая!{{else}}Вы такой взрослый!{{/eq}}
{{else}}
К сожалению, вам еще нет 16 лет
{{/gte}}
Comparison helpers for numeric values work only with numbers, and strings are written to variables in the bot components. Therefore, you need to use helper toInt inside these helpers to convert the values of variables from a string to a number. For example: {{#gte (toInt var1)(toInt var2)}}1{{else}}0{{/gte}}

All Comparison Helpers

#eq - are the variables equal?
{{#eq переменная1 переменная2}}
Если переменные равны
{{else}}
Необязательный текст, если переменные не равны
{{/eq}}
#lt - is the first variable less than the second one?
{{#lt переменная1 переменная2}}
Если первая переменная меньше
{{else}}
Необязательный текст, если вторая переменная меньше
{{/lt}}
#gt - is the first variable greater than the second?
{{#gt переменная1 переменная2}}
Если первая переменная больше
{{else}}
Необязательный текст, если вторая переменная больше
{{/gt}}
#if - does the variable exists and does it have "true value"?
{{#if переменная}}
Если переменная существует и в ней НЕ пустая строка "", ноль 0, логическая ложь false, ссылка на «ничего» null
{{else}}
Необязательные текст, для обратного условия
{{/if}}
#lte - is the first variable is less than or equal to the second one?
{{#lte age 16}}
К сожалению, ботом нельзя пользоваться до 16 лет
{{/lte}}
#gte - is the first variable greater than or equal to the second one?
{{#gte age 16}}
Ого! Добро пожаловать, вам так много лет!
{{/gte}}
Botmother supports other comparison helpers, but does not guarantee their work in future updates.