IF Else Statement not working

I tried creating a module that will create a variable greeting. For instance if property “A” is filled it should show “A + First Name + Last Name” if property “A” is not filled it should show “Hello First Name”. I tried to do this using the examples on the IF/Else documentation but its not working 100% correctly. Below is my code, can you tell me what I am doing wrong?

{% if contact.to_the_parents_and_guardians_of %}
{{contact.to_the_parents_and_guardians_of}} {{contact.firstname}} {{contact.lastname}},
{% else %}
Hello {{contact.firstname}},
{% endif %}

You could try it like that:

{% if contact.to_te_parents_and_guardians_of != "" %}
...
{% else %}
...
{% endif %}

Let me know if that works.

Fabian

thanks for your solution but that is not working for me either. For some reason the “else” portion gets ignored on your version and mine.

Then try to print out the empty value, maybe with:

{{ contact.to_the_parents_and_guardians_of|pprint }}

Your “empty” value could also contain brackets like “[]”. In this case you need to write it like that:

{% if contact.to_te_parents_and_guardians_of != "[]" %}
...
{% else %}
...
{% endif %}

Hey @mbattung

When you print the value and its possible option what do you see?

i.e:

{{ contact.to_the_parents_and_guardians_of }}

it give me “To the Parents or Guardians of” which is the set value for the property.

And what do you see, if it is empty? Try it with the suggested |pprint filter.

For using any Personalization Token in if/else condition, it is necessary to enable programmable email. And for that, you need to add isEnabledForEmailV3Rendering: true at the top of the template. For reference, please check the screenshot. For more, please go to this page.