# If else condition with personalization token

**URL:** <https://community.hubspot.com/t/if-else-condition-with-personalization-token/101896>\
**Category:** CMS Development\
**Tags:** starter\
**Created:** [March 6, 2024, 5:51pm UTC](https://community.hubspot.com/t/if-else-condition-with-personalization-token/101896 "2024-03-06T17:51:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![prathap](https://avatars.discourse-cdn.com/v4/letter/p/d78d45/32.png) [@prathap](https://community.hubspot.com/u/prathap)\
**Post date:** [March 6, 2024, 5:51pm UTC](https://community.hubspot.com/t/if-else-condition-with-personalization-token/101896/1 "2024-03-06T17:51:42Z")

</div>

Hi All,  
I am trying to fina a solution for the below querry. But the if else condition is not working(I tried for creating a seprate contact with firstname as unknown but its not working)  
Requirement:  
If the first name contains UNKNOWN or is equal to UNKNOWN (any case sensitive) then show a specific value.  
and the condition  
{% if contact.firstname.value == “Unknown” %}\<p\>Hello\</p\>{% else %} Hey {% endif %}  
Can you look into this and advise  
Thanks,  
Prathap

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [March 7, 2024, 4:46pm UTC](https://community.hubspot.com/t/if-else-condition-with-personalization-token/101896/2 "2024-03-07T16:46:59Z")

</div>

Hi, @prathap👋 Welcome to our community! Thank you for the great question.

It looks like you are on the right path. Have you tried using the [**lower**](https://developers.hubspot.com/docs/cms/hubl/filters#lower) filter to convert the contact.firstname.value to lowercase (or upper for uppercase) and then compare it to the lowercase (or uppercase) string you want to match?

Something like:

```lia-code-sample
{% if contact.firstname|lower == "unknown" %}<p>Hello</p>{% else %}<p>Hey</p>{% endif %}

```

Have fun building! — Jaycee

---

<div class="post-metadata">

**Author:** ![prathap](https://avatars.discourse-cdn.com/v4/letter/p/d78d45/32.png) [@prathap](https://community.hubspot.com/u/prathap)\
**Post date:** [March 7, 2024, 5:45pm UTC](https://community.hubspot.com/t/if-else-condition-with-personalization-token/101896/3 "2024-03-07T17:45:04Z")

</div>

[@Jaycee\_Lewis](https://community.hubspot.com/t5/user/viewprofilepage/user-id/127074) Thanks for your quick response.  
However i have tested this condition and matching condition is not working, only else condition is executing even if it matches the condition.  
Contact first name is prathap. I have tried with this contact but its not working.  
{% if contact.firstname == “prathap” %}\<p\>Hello\</p\>{% else %}\<p\>Hey\</p\>{% endif %}  
Can you lookinto this and let me know

---

<div class="post-metadata">

**Author:** ![albertsg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/albertsg/32/99473_2.png) [@albertsg](https://community.hubspot.com/u/albertsg)\
**Post date:** [March 7, 2024, 9:04pm UTC](https://community.hubspot.com/t/if-else-condition-with-personalization-token/101896/4 "2024-03-07T21:04:32Z")

</div>

@prathap Maybe try debugging it.

Are you sure {{contact.firstname}} is returning what you want? Try adding it above the IF statement just to print it and see what is the actual value.

Then you could try something like this:

`{% if contact.firstname is string_containing('unknown') %}<p>Hello</p>{% else %}<p>Hey</p>{% endif %}`

---

<div class="post-metadata">

**Author:** ![prathap](https://avatars.discourse-cdn.com/v4/letter/p/d78d45/32.png) [@prathap](https://community.hubspot.com/u/prathap)\
**Post date:** [March 8, 2024, 11:24am UTC](https://community.hubspot.com/t/if-else-condition-with-personalization-token/101896/5 "2024-03-08T11:24:06Z")

</div>

@albertsg I tried debuging it but not getting the expected result.  
{{ contact.firstname }} is fetching the expected value but if i use if else condition and this value is not matching.  
However i tried with first name default value(there), if else is working for this default value but not working for contacts value  
**Example** :  
Default value( **there** ); and the condition is executing  
{% if contact.firstname == “there” %}\<p\>Hello\</p\>{% else %}\<p\>Hey\</p\>{% endif %}  
Actual Contact or sample contact value( **prathap** ); and the condition is not executing  
{% if contact.firstname == “prathap” %}\<p\>Hello\</p\>{% else %}\<p\>Hey\</p\>{% endif %}

---

<div class="post-metadata">

**Author:** ![tyler-west](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tyler-west/32/44655_2.png) [@tyler-west](https://community.hubspot.com/u/tyler-west)\
**Post date:** [March 11, 2024, 1:48pm UTC](https://community.hubspot.com/t/if-else-condition-with-personalization-token/101896/6 "2024-03-11T13:48:57Z")

</div>

Hi @prathap !  
What if you save the name to a variable before running the if statement? I’ve had issues in a programmable email that required a saved variable in Hubl logic. Not sure if this will help you, but I figured I would share.

Example:

```lia-code-sample
{% set this_contact = contact.firstname %}
{% if this_contact == "prathap" %}
 <p>Hello</p>
{% else %}
 <p>Hey</p>
{% endif %}

```

---

<div class="post-metadata">

**Author:** ![albertsg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/albertsg/32/99473_2.png) [@albertsg](https://community.hubspot.com/u/albertsg)\
**Post date:** [March 11, 2024, 5:08pm UTC](https://community.hubspot.com/t/if-else-condition-with-personalization-token/101896/7 "2024-03-11T17:08:10Z")

</div>

To add to @tyler-west answer, try adding print the value with the filter |pprint to see more details about it.  
There is a page on HubSpot’s documentatio dedicated to debuggin that could be helpful in this situation: [Debugging methods and error types - HubSpot docs](https://developers.hubspot.com/docs/cms/developer-reference/debugging-and-errors#code-pprint-code-hubl-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:47am UTC](https://community.hubspot.com/t/if-else-condition-with-personalization-token/101896/8 "2024-03-20T08:47:47Z")

</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?_gl=1*j2rkar*_ga*OTEzMTYxMzU5LjE2OTU3OTU4MTk.*_ga_LXTM6CQ0XK*MTcxMDkyMTYyNi4xNS4xLjE3MTA5MjQzMzIuMjEuMC4w#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)
