• Got questions about HubSpot’s Smart CRM?

    Our product team is answering them live through March 6th!

    Ask us anything
  • Ready to build your local HubSpot community?

    HUG leaders host events, spark connections, and create spaces where people learn and grow together.

    Become a HUG Leader

Check if contact property is empty in email templates

MNick2
Participant

Hello, I am trying to figure out how to check if a contact property is empty via hubl we have so far

 

 

{% if contact.added_to_our_list_after is not defined or contact.added_to_our_list_after == '' or contact.added_to_our_list_after is none %}
<!-- Do something if the property is empty, not defined, or null -->
<p>The contact has not been added to our list after a specific date.</p>
{% else %}
<!-- Do something if the property is not empty -->
<p>The contact was added to our list after: {{ contact.added_to_our_list_after }}</p>
{% endif %}

 


But it doesn't work, it always goes into the else statement, so something I am clearly missing with the value of contact.added_to_our_list_after when blank

0 Upvotes
1 Accepted solution
Kevin-C
Solution
Recognized Expert | Partner
Recognized Expert | Partner

Hey @MNick2 

There is the "type" function that will function similarly to typeof in JS.

In your case its important to remember that date fields are nullable meaning these type of values are designed to hold a null value representing the absence of a value. Thus an "empty" date property will be null to represent the no date.

 

{{type(contact.added_to_our_list_after) == "null"}} {# true #}

 

 

You could also force a string value and check the length:

 

{% set temp_val = contact.added_to_our_list_after|string %}
{% if temp_val|length <=0 %} {# true %}
…

 

 

 

Hope this gets you going!

View solution in original post

6 Replies 6
MNick2
Participant

Yup, have done that.

 
Returns nothing, empty string is my assumption. Wish there was a TYPEOF or something.
 
But the property itself, is a empty string, where we can enter anything into it like "added after newsletter" etc, just a basic string.
 
But when it's empty, nothing there, no conditional ideas are working in email templates to check if it's empty.
0 Upvotes
Jaycee_Lewis
Thought Leader

Hey, @MNick2 👋 I have a few additional troubleshooting questions for you:

— Have you tried adding a temporary debugging line in your template to output the value of contact.added_to_our_list_after to see what is actually being returned? This may help you understand why the logic might be falling into the else statement.

<p>Debug: {{ contact.added_to_our_list_after }}</p>

 

— Ensure that contact.added_to_our_list_after is being returned as a string. Sometimes date fields might behave differently, especially if they are being treated as Date objects. If so, 

comparing it against a default date might help:

{% if contact.added_to_our_list_after == '1970-01-01T00:00:00Z' or contact.added_to_our_list_after == '' or contact.added_to_our_list_after is none %}

 

If you've already ruled these out, or they don't help, please let me know, and we can tag in a few of our community members who are experts with HubL.

 

Talk soon! — Jaycee





loop


Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.

Learn More




0 Upvotes
MNick2
Participant
Yup, have done that.

Returns nothing, empty string is my assumption. Wish there was a TYPEOF or
something.

But the property itself, is a empty string, where we can enter anything
into it like "added after newsletter" etc, just a basic string.

But when it's empty, nothing there, no conditional ideas are working in
email templates to check if it's empty.
0 Upvotes
Jaycee_Lewis
Thought Leader

Thanks @Kevin-C 🙌





loop


Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.

Learn More




Kevin-C
Solution
Recognized Expert | Partner
Recognized Expert | Partner

Hey @MNick2 

There is the "type" function that will function similarly to typeof in JS.

In your case its important to remember that date fields are nullable meaning these type of values are designed to hold a null value representing the absence of a value. Thus an "empty" date property will be null to represent the no date.

 

{{type(contact.added_to_our_list_after) == "null"}} {# true #}

 

 

You could also force a string value and check the length:

 

{% set temp_val = contact.added_to_our_list_after|string %}
{% if temp_val|length <=0 %} {# true %}
…

 

 

 

Hope this gets you going!

Jaycee_Lewis
Thought Leader

Hey, @Anton @alyssamwilie @Stephanie-OG, do you have any additional troubleshooting tips for @MNick2?

 

Thank you! — Jaycee





loop


Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.

Learn More




0 Upvotes