Similar to using the show/hide function, using If/Endif statements can be used to show certain copy if the viewer meets the if/endif statement requirements, based on their saved profile properties. IE: You have a form on your website that asks if customers prefer cats or dogs as a pet. The customer fills in the form with their email address, stating they like dogs. A different customer fills in the form saying they like cats. In an email template, you can write an if/endif statement that directs customers who filled in ‘dogs’ to see one statement, and a different statement for customers who filled in ‘cats’ to see a different statement.
The if/endif statement for this would look like the following:
{% if person|lookup:'Interested in Dogs?' and not person|lookup:'Interested in Cats?' %}
Like dogs? Check out some great toys for your canine.
{% elif person|lookup:'Interested in Cats?' and not person|lookup:'Interested in Dogs?' %}
Like cats? Check out some great toys for your feline.
{% else %} Check out some great toys for your pet!
{% endif %}
When writing an if/endif statement based on a saved profile property, the statement will always include person|lookup: ‘Profile Property name here’.
This is because we’re having the if/endif function look on the viewer’s profile for this property, and display the following condition, if they have that property, with the statement you added after (IE: the function is looking for the profile property ‘interested in dogs’ and if yes, showing ‘Like dogs?...’).
‘If statements’ should follow this general structure. The conditions in ALL CAPS are placeholders.
{% if CONDITION_1 %}
Content to show if CONDITION_1 is true.
{% elif CONDITION_2 %}
If CONDITION_1 is not true, but CONDITION_2 is true, show this content instead.
"Elif" statements are optional.
{% else %}
If none of the above conditions are true, show this content.
"Else" statement is optional.
{% endif %}
The tags {% elif %} and {% else %} are completely optional. Any amount of {% elif %} tags can be used to define alternate conditions and only one {% else %} should be used to define default content if desired. However, {% endif %} is absolutely necessary to end the if statements.
More information on this can be found here.
More information on profile properties can be found here.