# HubL string comparison fails

**URL:** <https://community.hubspot.com/t/hubl-string-comparison-fails/144878>\
**Category:** CMS Development\
**Tags:** design-manager, email, html\
**Created:** [January 13, 2026, 6:27pm UTC](https://community.hubspot.com/t/hubl-string-comparison-fails/144878 "2026-01-13T18:27:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![birdman](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/birdman/32/5619_2.png) [@birdman](https://community.hubspot.com/u/birdman)\
**Post date:** [January 13, 2026, 6:27pm UTC](https://community.hubspot.com/t/hubl-string-comparison-fails/144878/1 "2026-01-13T18:27:45Z")

</div>

Contact has a single line text property preferred\_branch. Contact record values are “ijmuiden”, “velserbroek”, or empty.  
From Design Manager \> Email template (HTML and HubL)

{% set branch\_key = contact.preferred\_branch %}  
\*{{ branch\_key }}\*  
{{ branch\_key }}  
{% if branch\_key == “ijmuiden” %}  
IJMUIDEN  
{% elif branch\_key == “velserbroek” %}  
VELSERBROEK  
{% else %}  
UNKNOWN  
{% endif %}  
{{ crm\_objects(“contact”, “preferred\_branch\_\_eq=ijmuiden”, “preferred\_branch”) }}  
Email based on this template returns (in Preview mode, for contact with valure “ijmuiden”):  
\*ijmuiden\* ijmuiden UNKNOWN {has\_more=false, offset=6, total=6, results=[{preferred\_branch=ijmuiden, id=185050575243}, {preferred\_branch=ijmuiden, id=185050965806}, {preferred\_branch=ijmuiden, id=185058236162}, {preferred\_branch=ijmuiden, id=185059223056}, {preferred\_branch=ijmuiden, id=185061766250}, {preferred\_branch=ijmuiden, id=185061766251}]}

Why is the string comparison failing?

---

<div class="post-metadata">

**Author:** ![Victor\_Becerra](https://avatars.discourse-cdn.com/v4/letter/v/87869e/32.png) [@Victor\_Becerra](https://community.hubspot.com/u/Victor_Becerra)\
**Post date:** [January 14, 2026, 1:44pm UTC](https://community.hubspot.com/t/hubl-string-comparison-fails/144878/2 "2026-01-14T13:44:37Z")

</div>

Hi @birdman

Thanks for sharing this — string comparisons in HubL can definitely be tricky even when the value _looks_ correct.

I’ll loop in a few Community members who are very familiar with HubL and email template behavior to weigh in here.  
@SteveHTM @alyssamwilie @BarryGrennan — have you seen cases where a HubL string renders correctly but fails an if == comparison? Any known quirks around whitespace, encoding, or email preview context that could explain this?

Appreciate any insight you can share.  
Victor

---

<div class="post-metadata">

**Author:** ![birdman](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/birdman/32/5619_2.png) [@birdman](https://community.hubspot.com/u/birdman)\
**Post date:** [January 14, 2026, 2:40pm UTC](https://community.hubspot.com/t/hubl-string-comparison-fails/144878/3 "2026-01-14T14:40:33Z")

</div>

Thanks [@Victor\_Becerra](https://community.hubspot.com/t5/user/viewprofilepage/user-id/620965) - I have tried Trim, no success. Lenght is also interesting. It does not return the actual string length but always the same length. If have tried ==, but also ‘IS’.  
Hopefully an enligthed spirit will show me the way.

---

<div class="post-metadata">

**Author:** ![SteveHTM](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/stevehtm/32/22074_2.png) [@SteveHTM](https://community.hubspot.com/u/SteveHTM)\
**Post date:** [January 14, 2026, 5:01pm UTC](https://community.hubspot.com/t/hubl-string-comparison-fails/144878/4 "2026-01-14T17:01:25Z")

</div>

@birdman - I have to say that I am mystified by this one. I have confirmed your observations about the ‘==’ and ‘is string\_containing’ tests in an email template, but I think this is not a general string comparison failure, but one that is specific to the manipulation/testing of personalization tokens in the context of an email.

As far as I can tell, all the equality tests perform ‘properly’ in the context of a web page or custom module, and also perform ‘properly’ when the string involved does NOT come from a object reference (a Contact personalization reference at least).

So, is this a bug or an undocumented limitation? I see there is a limitation on the use of HubL filters on personalization tokens in emails - perhaps this is related?

Hope this is helpful.

Steve

---

<div class="post-metadata">

**Author:** ![evaldas](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/evaldas/32/69160_2.png) [@evaldas](https://community.hubspot.com/u/evaldas)\
**Post date:** [January 14, 2026, 5:52pm UTC](https://community.hubspot.com/t/hubl-string-comparison-fails/144878/5 "2026-01-14T17:52:00Z")

</div>

Hey @birdman,

Do you have [programmable email](https://knowledge.hubspot.com/marketing-email/create-programmable-emails) setting turned on?

I did a quick test with an email module:

 ![evaldas_0-1768412860410.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/f/0/f023adfc9706d68e5bf9c72042f3fb3585b8879e.png)

```lia-code-sample
{% set firstname = contact.firstname %}

{% if firstname == "John" %}
HEY JOHN
{% elif firstname == "Tom" %}
HEY TOM
{% else %}
HEY STRANGER
{% endif %}

```

When I preview the email with a contact that matches the first name, I am getting the correct greeting with the example above.

---

<div class="post-metadata">

**Author:** ![birdman](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/birdman/32/5619_2.png) [@birdman](https://community.hubspot.com/u/birdman)\
**Post date:** [January 15, 2026, 3:12pm UTC](https://community.hubspot.com/t/hubl-string-comparison-fails/144878/6 "2026-01-15T15:12:28Z")

</div>

Hello @evaldas - thanks for your answer. This is indeed the solution.  
The option ‘Use module for programmable email’ is only available when creating a module  
(HTML/CSS/JS), not when creating a template (HTML/HubL).  
In my case it seems I have to add in the header ‘--\>: isEnabledForEmailV3Rendering: true’, as stated in the KB article you refer to.
