Can you use hubl in email templates?

It is not clear from the documentation. If I can use it, how? Do I just go into the source code of the email and write hubl?

For instance, in an email template, I want logic like:

{% if contact.membership_type ==“member” %}

Say some member stuff

{% endif %}

Hi, @a_funs :waving_hand: Thanks for your question. The short answer is yes you can. It might look like this (simple example):

{% if contact.membership_type == "member" %}
 <p>Say some member stuff</p>
{% endif %}

If you want a quick way to test this out, you can:

  • Navigate to the Design Manager
  • File
  • New File
  • HTML + HubL
  • Email template

and experiment from there.

If you build something out, and it won’t work as expected, adding your example here as a code block helps the community better understand the issue. And I can try inviting some community members to join us as well.

Best,

Jaycee

Thanks. So is this answer outdated? https://community.hubspot.com/t5/Email-Marketing-Tool/HubL-using-custom-contact-properties-in-if-statements-in-an/m-p/315370/highlight/true#M3804
I want to be able to use `if` statements to show content conditionally based on whether a custom property = “” (empty string) or not.
I’m having trouble finding the answer in Email template markup - HubSpot docs
Thanks!

Where you able to find a solution to this? I am currently running into the same issue.

Hi @a_funs

Yes, HubL can be used in emails, but there’s an important difference between coded and drag-and-drop emails. If you’re using a custom coded email template created in Design Manager, you can add HubL conditions directly in the template code, such as {% if contact.membership_type == ""member"" %} ... {% endif %}.

For drag-and-drop emails created directly in the email editor, you generally wouldn’t add HubL directly into the email content. In that case, I’d recommend using HubSpot’s personalization or smart content features to show different content based on contact properties.

Also, make sure membership_type is the actual internal name of the contact property, and test the email with contacts that have different values before sending.

I hope this helps you out. Please mark it as Solution Accepted and Like to help another Community member.
This post was created with the assistance of AI tools

Thanks!