CMS Development

RhodriJ
Member

HubL String Comparison

Hi, I'm having trouble using HubL with a basic string comparison which I'm hoping someone can spot where I'm going wrong.

 

 

// {{ contact.hubspot_owner_id.email }} renders email@example.com
{% if contact.hubspot_owner_id.email == "email@example.com" %}

True

{% endif %}

 

 

When I render the email property into the email it does appear to be the same, though HubL doesn't think that is the case and evaluates as false. It does appear to evaluate as true when I compare 2 hard coded strings but having no luck when using an object property. Could it be that the email property is not a string? I have tried the 'string' and 'trim' filters but that doesn't seem to change anything.

 

What's also strange is that in the email template editor it seems to evaluate as true and renders the block of HTML, but when sending an email preview to my inbox it doesn't seem to be the case even though the email property is exactly the same.

 

Any help is greatly appreciated,

Thank you

7 Replies 7
DATADEER
Member

HubL String Comparison

Try activating the "Programmable email module" Beta in the respective Module.
For me it worked after turning it on. Not sure if it was truly related or whether some cache just refreshed after turning this on. I could then use conditions like.

 

{% if deal.quality_level == "GOOD" %}
<h1>good stuff</h1>
{% endif %}

 

programmable email.png

 

 

 

 

0 Upvotes
a_funs
Contributor

HubL String Comparison

I can confirm I have the same issue..

0 Upvotes
a_funs
Contributor

HubL String Comparison

I can't believe this does not work, there is no way to do this in a template. On any other email marketing platform, this is the most simple functionality. Likely they implemented it DAY 1!

0 Upvotes
webdew
Guide | Diamond Partner
Guide | Diamond Partner

HubL String Comparison

Hi @RhodriJ ,

Try the following steps:

  1. Check which type of values return by contact.hubspot_owner_id.email
  2. If this returns array then please try following code:

 

{% set dummyEmail = "email@example.com" %}

{% if contact.hubspot_owner_id.email[0] == dummyEmail %}

True

{% endif %}

 

  1. If it return single value then please try following code:

 

{% set dummyEmail = "email@example.com" %}

{% if contact.hubspot_owner_id.email == dummyEmail %}

True

{% endif %}

Hope this helps!
If we were able to answer your query, kindly help the community by marking it as a solution.
Thanks and Regards.

0 Upvotes
RhodriJ
Member

HubL String Comparison

Hi @webdew,

 

Thank you for your input and help. 

 

The type function does seem to be returning "str" rather than an array. When I set the dummy email, it renders true in the email template but when it's sent to an inbox as a preview this isn't the case even though the contact owner email value is exactly the same.

 

Any further suggestions would be greatly appreciated, as I've started to run out of ideas here.

Thanks!

0 Upvotes
DNguyen508
Member

HubL String Comparison

@RhodriJ- Do you have a solution for this? I'm having the same problem with you.
Thanks,

dennisedson
HubSpot Product Team
HubSpot Product Team

HubL String Comparison

@piersg , what are your thoughts?

0 Upvotes