A statement is a command given by you to take specific actions, and is used to describe a behavior or a logic.
IF Statement
In the case of an IF statement, you set a condition that can be evaluated as true or false. For example: if gender equals male is true. Based on the result, you can define an action: if gender equals male is true, write Mr. Last Name.
A statement may have internal components for example expressions like a personalization field. In case you need to define a statement, start it with a curly bracket followed by a percent sign and close it with a percent and a closing curly bracket. Between these, you need an actual statement defining what happens in all possible cases.
{% this is a statement %}
IF Statement with length filter
Let us have a look at another example. If the first name of your contact has 6 characters or more, display the words ‘Hello friend’, otherwise display ‘Hello first name’.
{% if contact.1|length>=6%} Hello Friend {%else%} Hello {{ Contact.1 }} {%endif%}
For this statement, I need to use the filter called length, which counts the length of the given word. So, if your contact is called Jonathan, the word ‘friend’ will be shown, but if the first name is just John, we can display that because it’s only 4 characters long. If you’d like to combine the two previous examples in a statement, you need to start by checking whether the first name has a value, and then continue as before.
If statement in the VCE editor
This is what you can see in the VCE editor when the If statement with length filter ESL snippet is added:
In our example, the first name has exactly 4 characters, so only the “Hello Friend” greeting will appear.
This is how it looks like in the Contact Preview, what your user can see:
A little syntax recap for you:
{{ this is an expression }}
{% this is a statement %}
|this is a filter