# Email module: check if contact variable empty

**URL:** <https://community.hubspot.com/t/email-module-check-if-contact-variable-empty/90378>\
**Category:** CMS Development\
**Tags:** design-manager\
**Created:** [September 25, 2023, 10:25am UTC](https://community.hubspot.com/t/email-module-check-if-contact-variable-empty/90378 "2023-09-25T10:25:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MBent](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@MBent](https://community.hubspot.com/u/MBent)\
**Post date:** [September 25, 2023, 10:25am UTC](https://community.hubspot.com/t/email-module-check-if-contact-variable-empty/90378/1 "2023-09-25T10:25:18Z")

</div>

Hi there,

I have created a custom email module, with the following code

`<p>Dear {% if contact.firstname != "" and contact.lastname != "" %}{{contact.firstname}} {{contact.lastname}}{% else %}Mr./Mrs{% endif %},</p>`

I also changed on of our contacts to have an empty lastname

But when i send a test mail using that contact’s info the if statement doesnt seen the lastname as being an empty string. end it just prints the values eventhough lastname is empty.

Could this be a problem with the test email option? or am i missing something?

---

<div class="post-metadata">

**Author:** ![zachh](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zachh/32/87065_2.png) [@zachh](https://community.hubspot.com/u/zachh)\
**Post date:** [September 25, 2023, 12:37pm UTC](https://community.hubspot.com/t/email-module-check-if-contact-variable-empty/90378/2 "2023-09-25T12:37:04Z")

</div>

Hi @MBent,

Are you able to confirm that the empty lastname property is seen an empty string? If it’s a null value, or anything other than an empty string, that statement will still register as TRUE.

Can you try to change your if statement to look more like _contact.lastname.value_ instead of _contact.lastname != “”_ and see what that does for you?

- Zach

---

<div class="post-metadata">

**Author:** ![MBent](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@MBent](https://community.hubspot.com/u/MBent)\
**Post date:** [September 25, 2023, 1:04pm UTC](https://community.hubspot.com/t/email-module-check-if-contact-variable-empty/90378/3 "2023-09-25T13:04:46Z")

</div>

Hi @zachh,

Thanks for your suggestions.

The lastname value for this contact should be empty.

I removed any value from its field on the edit contact page.

I tried contact.lastname.value, but that doesnt make any difference! It also doesnt print anything. contact.firstname.value also has no value. So i dont think value is a value on this object!

Is there anyway i can check what contact.lastname actualy returns?

---

<div class="post-metadata">

**Author:** ![MBent](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@MBent](https://community.hubspot.com/u/MBent)\
**Post date:** [September 25, 2023, 1:12pm UTC](https://community.hubspot.com/t/email-module-check-if-contact-variable-empty/90378/4 "2023-09-25T13:12:56Z")

</div>

{{contact.lastname|pprint }} prints (String: )

---

<div class="post-metadata">

**Author:** ![zachh](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zachh/32/87065_2.png) [@zachh](https://community.hubspot.com/u/zachh)\
**Post date:** [September 25, 2023, 1:26pm UTC](https://community.hubspot.com/t/email-module-check-if-contact-variable-empty/90378/5 "2023-09-25T13:26:46Z")

</div>

I found [this community post from April](https://community.hubspot.com/t5/CMS-Development/Help-with-HubL/td-p/781722) where they are using _‘none’_ instead of an empty string. Can you try that to see if it works?

If pprint is showing that, it’s identifying it as a string, so I’m wondering if Hubspot uses some default null value. I’m having a hard time finding documentation that speaks to this.

[Edited to add link to post]

---

<div class="post-metadata">

**Author:** ![MBent](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@MBent](https://community.hubspot.com/u/MBent)\
**Post date:** [September 26, 2023, 7:32am UTC](https://community.hubspot.com/t/email-module-check-if-contact-variable-empty/90378/6 "2023-09-26T07:32:24Z")

</div>

Hey @zachh

Thanks again for your suggestions!

I have the same issue with the documentation.

I’ve now tried:

`<p>Dear {% if contact.firstname.value is none or contact.lastname.value is none %}Mr./Mrs{% else %}{{contact.firstname}} {{contact.lastname}}{% endif %},</p>`

and

`<p>Dear {% if contact.firstname is none or contact.lastname is none %}Mr./Mrs{% else %}{{contact.firstname}} {{contact.lastname}}{% endif %},</p>`

and

`<p>Dear {% if contact.firstname is blank or contact.lastname is blank %}Mr./Mrs{% else %}{{contact.firstname}} {{contact.lastname}}{% endif %},</p>`

All of them dont work!

Thanks again for trying to help! i;m goiung to keep hacking at this!

If you come up with any more suggestions please let me know!

---

<div class="post-metadata">

**Author:** ![zachh](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zachh/32/87065_2.png) [@zachh](https://community.hubspot.com/u/zachh)\
**Post date:** [September 26, 2023, 12:26pm UTC](https://community.hubspot.com/t/email-module-check-if-contact-variable-empty/90378/7 "2023-09-26T12:26:14Z")

</div>

Just for the sake of clarification, you are enrolled in the beta for this feature, correct?

> **[Create programmable emails](https://knowledge.hubspot.com/marketing-email/create-programmable-emails)**
>
> Learn how to create programmable emails in HubSpot (BETA).

---

<div class="post-metadata">

**Author:** ![MBent](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@MBent](https://community.hubspot.com/u/MBent)\
**Post date:** [September 29, 2023, 9:47am UTC](https://community.hubspot.com/t/email-module-check-if-contact-variable-empty/90378/8 "2023-09-29T09:47:21Z")

</div>

Hey @zachh

Just to let you know, i tried it with both this setting on and off! It makes no difference.

So i gave up.

The workaround im using right now is updating all contacts with a salutation field where i combine the first and last names using a script, and adding Mr/Mrs to the field where the names are empty.

Thanks for trying to help! Very much appreciated!

Cheers!
