# If statement to check if personalization token is empty

**URL:** <https://community.hubspot.com/t/if-statement-to-check-if-personalization-token-is-empty/46459>\
**Category:** CMS Development\
**Created:** [November 4, 2021, 8:24am UTC](https://community.hubspot.com/t/if-statement-to-check-if-personalization-token-is-empty/46459 "2021-11-04T08:24:49Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChrisChiha](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/chrischiha/32/90510_2.png) [@ChrisChiha](https://community.hubspot.com/u/ChrisChiha)\
**Post date:** [November 4, 2021, 8:24am UTC](https://community.hubspot.com/t/if-statement-to-check-if-personalization-token-is-empty/46459/1 "2021-11-04T08:24:49Z")

</div>

Hello,

I am creating a module in which i want to check if my personalization token is empty.

personalization token is {{personalization\_token(“contact.firstname”, " ")}} .  
If personalization token has value, i want to display " Hello, {{personalization\_token(“contact.firstname”, " “)}}”

If the personalization token is empty, i want to display a new html text section.  
So far i have this code, would appreciate some help on where i need to modify it for it to work.

{% set Value = personalization\_token(“contact.firstname”,“Null”) %}  
{% set NewValue = Value %}

{% if NewValue == “Null” %}  
\<p\>  
Glad to have you with us!  
\</p\>

{% elif %}

\<p\>  
Hello, {{personalization\_token(‘contact.firstname’, ’ ') }}  
\</p\>

{% endif %}

---

<div class="post-metadata">

**Author:** ![Oezcan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/oezcan/32/53959_2.png) [@Oezcan](https://community.hubspot.com/u/Oezcan)\
**Post date:** [November 4, 2021, 10:45am UTC](https://community.hubspot.com/t/if-statement-to-check-if-personalization-token-is-empty/46459/2 "2021-11-04T10:45:59Z")

</div>

Hello @ChrisChiha,

try this!

```lia-code-sample
{% unless contact.firstname =="" %}
{{ contact.firstname }}
{% else %}
HTML
{% endunless %}

```

best regards

Özcan

---

<div class="post-metadata">

**Author:** ![ChrisChiha](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/chrischiha/32/90510_2.png) [@ChrisChiha](https://community.hubspot.com/u/ChrisChiha)\
**Post date:** [November 4, 2021, 10:54am UTC](https://community.hubspot.com/t/if-statement-to-check-if-personalization-token-is-empty/46459/3 "2021-11-04T10:54:14Z")

</div>

I tried it.

It is showing contact name in both cases.  
If there’s value it is showing the name, if it is empty it is showing blank space. Thoughts ?

---

<div class="post-metadata">

**Author:** ![SIllath](https://avatars.discourse-cdn.com/v4/letter/s/8491ac/32.png) [@SIllath](https://community.hubspot.com/u/SIllath)\
**Post date:** [February 26, 2022, 6:15pm UTC](https://community.hubspot.com/t/if-statement-to-check-if-personalization-token-is-empty/46459/4 "2022-02-26T18:15:08Z")

</div>

Hi @ChrisChiha,

Were you able to find a solution? I hqve been trying to use if statement to hide table content when personalization token value is empty. Please let me know, if you were able to find a solution. TIA!

---

<div class="post-metadata">

**Author:** ![ChrisChiha](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/chrischiha/32/90510_2.png) [@ChrisChiha](https://community.hubspot.com/u/ChrisChiha)\
**Post date:** [February 27, 2022, 12:41pm UTC](https://community.hubspot.com/t/if-statement-to-check-if-personalization-token-is-empty/46459/5 "2022-02-27T12:41:55Z")

</div>

Hello @SIllath ,  
Yes it worked.

I am using this code to display/hide content when personalization token is empty:

{% unless deal.customer\_full\_name ==“” %}  
\<!-- Section applicable if personalization token is not empty --\>

{% else %}  
\<!-- Section applicable if personalization token is empty --\>

{% endunless %}

---

<div class="post-metadata">

**Author:** ![SIllath](https://avatars.discourse-cdn.com/v4/letter/s/8491ac/32.png) [@SIllath](https://community.hubspot.com/u/SIllath)\
**Post date:** [February 27, 2022, 5:29pm UTC](https://community.hubspot.com/t/if-statement-to-check-if-personalization-token-is-empty/46459/6 "2022-02-27T17:29:29Z")

</div>

Hi@ChrisChiha,

Thank you so much for your response. Is there anything different in the above conditional statement, if we have a custom object?

Thanks!

---

<div class="post-metadata">

**Author:** ![Oezcan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/oezcan/32/53959_2.png) [@Oezcan](https://community.hubspot.com/u/Oezcan)\
**Post date:** [November 4, 2021, 11:02am UTC](https://community.hubspot.com/t/if-statement-to-check-if-personalization-token-is-empty/46459/7 "2021-11-04T11:02:35Z")

</div>

Will the HTML from my code be diplayed when firstname is missing?

Have you inserted your function/text which should be displayed as fallback?

The blank space is an indicator for missing informations/data.

Have you entered a default value for your fallback? Like your welcome message.

best regards

Özcan

---

<div class="post-metadata">

**Author:** ![ChrisChiha](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/chrischiha/32/90510_2.png) [@ChrisChiha](https://community.hubspot.com/u/ChrisChiha)\
**Post date:** [November 4, 2021, 11:04am UTC](https://community.hubspot.com/t/if-statement-to-check-if-personalization-token-is-empty/46459/8 "2021-11-04T11:04:41Z")

</div>

I used this, When there’s value it displayed : Hey, Value  
When it is empty, it displayed : Hey,

```lia-code-sample
{% unless contact.firstname =="" %}
Hey, {{ contact.firstname }}
{% else %}
Empty
{% endunless %}

```

---

<div class="post-metadata">

**Author:** ![Oezcan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/oezcan/32/53959_2.png) [@Oezcan](https://community.hubspot.com/u/Oezcan)\
**Post date:** [November 4, 2021, 11:14am UTC](https://community.hubspot.com/t/if-statement-to-check-if-personalization-token-is-empty/46459/9 "2021-11-04T11:14:07Z")

</div>

Are you looking/testing it in the preview of the page/email? Because, unless u select proper contact for preview it will be displayed either as CONTACT.FIRSTNAME or “blank”.

Also I would recomend to get the personalition token right by openning an richtext function selecting the right token and copy it from the source code.

Best

Özcan

---

<div class="post-metadata">

**Author:** ![ChrisChiha](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/chrischiha/32/90510_2.png) [@ChrisChiha](https://community.hubspot.com/u/ChrisChiha)\
**Post date:** [November 4, 2021, 11:24am UTC](https://community.hubspot.com/t/if-statement-to-check-if-personalization-token-is-empty/46459/10 "2021-11-04T11:24:31Z")

</div>

Yes, i am following the above steps. Tried different approaches, i am losing hope.

---

<div class="post-metadata">

**Author:** ![ChrisChiha](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/chrischiha/32/90510_2.png) [@ChrisChiha](https://community.hubspot.com/u/ChrisChiha)\
**Post date:** [November 4, 2021, 11:26am UTC](https://community.hubspot.com/t/if-statement-to-check-if-personalization-token-is-empty/46459/11 "2021-11-04T11:26:26Z")

</div>

Is there any other way top specify if a value is null other than ==“” ?

---

<div class="post-metadata">

**Author:** ![Oezcan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/oezcan/32/53959_2.png) [@Oezcan](https://community.hubspot.com/u/Oezcan)\
**Post date:** [November 4, 2021, 11:31am UTC](https://community.hubspot.com/t/if-statement-to-check-if-personalization-token-is-empty/46459/12 "2021-11-04T11:31:42Z")

</div>

Have you selected a contact for preview?

 ![Oezcan_0-1636025294542.jpg](https://d2qpr2jzcazej7.cloudfront.net/original/3X/f/5/f57a4bd89a9060e7c724c175b8cf2454ce6acbc0.jpeg)

You can modify the code to:

```lia-code-sample
{% if contact.firstname !="" %}
HTML
{% else %}
{{ contact.firstname }}
{% endif %}

```

Best

Özcan

---

<div class="post-metadata">

**Author:** ![ChrisChiha](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/chrischiha/32/90510_2.png) [@ChrisChiha](https://community.hubspot.com/u/ChrisChiha)\
**Post date:** [November 4, 2021, 11:42am UTC](https://community.hubspot.com/t/if-statement-to-check-if-personalization-token-is-empty/46459/13 "2021-11-04T11:42:28Z")

</div>

Yes that’s where i am choosing contacts.  
For this code, i am having HTML displayed whenever i choose any contact (whether the first name has value or not). Just to be clear, i created a module and i am executing this code inside it

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

```

---

<div class="post-metadata">

**Author:** ![Oezcan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/oezcan/32/53959_2.png) [@Oezcan](https://community.hubspot.com/u/Oezcan)\
**Post date:** [November 4, 2021, 11:47am UTC](https://community.hubspot.com/t/if-statement-to-check-if-personalization-token-is-empty/46459/14 "2021-11-04T11:47:37Z")

</div>

Is there something else in the module?

---

<div class="post-metadata">

**Author:** ![ChrisChiha](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/chrischiha/32/90510_2.png) [@ChrisChiha](https://community.hubspot.com/u/ChrisChiha)\
**Post date:** [November 4, 2021, 11:55am UTC](https://community.hubspot.com/t/if-statement-to-check-if-personalization-token-is-empty/46459/15 "2021-11-04T11:55:41Z")

</div>

It finally worked, had some isues with my hubspot session.  
Cheers !
