# IF Else Statement not working

**URL:** <https://community.hubspot.com/t/if-else-statement-not-working/20577>\
**Category:** CMS Development\
**Created:** [May 4, 2020, 6:20pm UTC](https://community.hubspot.com/t/if-else-statement-not-working/20577 "2020-05-04T18:20:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbattung](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mbattung/32/31639_2.png) [@mbattung](https://community.hubspot.com/u/mbattung)\
**Post date:** [May 4, 2020, 6:20pm UTC](https://community.hubspot.com/t/if-else-statement-not-working/20577/1 "2020-05-04T18:20:53Z")

</div>

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 %}

---

<div class="post-metadata">

**Author:** ![FabianRichter](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/fabianrichter/32/79091_2.png) [@FabianRichter](https://community.hubspot.com/u/FabianRichter)\
**Post date:** [May 5, 2020, 8:39am UTC](https://community.hubspot.com/t/if-else-statement-not-working/20577/2 "2020-05-05T08:39:12Z")

</div>

You could try it like that:

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

```

Let me know if that works.

Fabian

---

<div class="post-metadata">

**Author:** ![mbattung](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mbattung/32/31639_2.png) [@mbattung](https://community.hubspot.com/u/mbattung)\
**Post date:** [May 13, 2020, 4:26pm UTC](https://community.hubspot.com/t/if-else-statement-not-working/20577/3 "2020-05-13T16:26:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![FabianRichter](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/fabianrichter/32/79091_2.png) [@FabianRichter](https://community.hubspot.com/u/FabianRichter)\
**Post date:** [May 15, 2020, 12:24pm UTC](https://community.hubspot.com/t/if-else-statement-not-working/20577/4 "2020-05-15T12:24:31Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![Kevin-C](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kevin-c/32/34570_2.png) [@Kevin-C](https://community.hubspot.com/u/Kevin-C)\
**Post date:** [May 13, 2020, 6:25pm UTC](https://community.hubspot.com/t/if-else-statement-not-working/20577/5 "2020-05-13T18:25:48Z")

</div>

Hey @mbattung

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

i.e:

`{{ contact.to_the_parents_and_guardians_of }}`

---

<div class="post-metadata">

**Author:** ![mbattung](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mbattung/32/31639_2.png) [@mbattung](https://community.hubspot.com/u/mbattung)\
**Post date:** [May 13, 2020, 6:49pm UTC](https://community.hubspot.com/t/if-else-statement-not-working/20577/6 "2020-05-13T18:49:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![FabianRichter](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/fabianrichter/32/79091_2.png) [@FabianRichter](https://community.hubspot.com/u/FabianRichter)\
**Post date:** [May 29, 2020, 7:17am UTC](https://community.hubspot.com/t/if-else-statement-not-working/20577/7 "2020-05-29T07:17:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Bhargavi2503](https://avatars.discourse-cdn.com/v4/letter/b/13edae/32.png) [@Bhargavi2503](https://community.hubspot.com/u/Bhargavi2503)\
**Post date:** [March 20, 2024, 8:44am UTC](https://community.hubspot.com/t/if-else-statement-not-working/20577/8 "2024-03-20T08:44:24Z")

</div>

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](https://developers.hubspot.com/docs/cms/hubl/if-statements#basic-if-statement-syntax:~:text=Please%20note%3A%20if%20you%27re%20using%20personalization%20tokens%20within%20a%20conditional%20statement%20of%20your%20email%20module%2C%20you%20must%20enable%20programmable%20email%20for%20the%20module.).

 ![evaldas_1-1747668064680.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/4/489753dd74893d1224f45271aa3f157f8e7066a8.png)
