Using contact custom fields in HTML email template

SOLVE
Highlighted
Regular Contributor

Update: I got to the end of writing this and realised I could actually achieve what I needed by creating a custom module with some smart content in it. (which is a better and more scalable, versitile way of doing things anyway). However, if anyone can be bothered reading through the below, I'd still be interested to know what I was doing wrong with my other approach (non urgent, so only if you're feeling bored Smiley Very Happy :

 

Scratching my head a little here - I've got a contact property called Primary Subscription which I'd like to use in a conditional statement in our email templates to display a different header based on what the contact's Primary Subscription property value is.

 

When I simply add {{ contact.primary_subscription }} to the template, it works fine - the value is output to the email body as expected in both the preview inside HubSpot and when sent as a preview email.

 

 

Screen Shot 2019-07-30 at 11.51.05 AM.png

 

 

However, using it in the below code doesn't seem to work, the default is always served when previewing the email, even when I can see 'EXJournal' output at the top of the message, which matches the value I'm using in the if statment.

 

{% if contact.primary_subscription == "EXJournal" %}
  <tr id="logo-header">
    <td align="center" class="bodyContent roboto-text" style="text-size-adjust: 100%; font-size: 14px; line-height: 15px; padding: 20px;{% if widget_data.show_header.value == 'Hide' %} padding-top: 40px;{% endif %} text-align: left; background-color: #FFFFFF; border-radius: 5px 5px 0px 0px;" valign="top"> <a href="{% text "main_website_link" label="Main Website Link", value="https://www.joyoushq.com", no_wrapper=True %}{% text "tracking_string" label="Tracking String", value="?utm_source=email&utm_channel=nurture&utm_campaign=customer_welcome", no_wrapper=True %}" style="text-align: center"> <img alt="" border="0" src="https://pulse.joyoushq.com/hubfs/images/exjournal/EXJ-Logo-gradient-455px.png?noresize" width="200" style="width:200px; margin: auto; max-width: 80%; border-width: 0px; border-style: solid;" /> </a> </td>
    <td align="center" class="bodyContent roboto-text" style="text-size-adjust: 100%; font-size: 14px; line-height: 15px; padding: 20px;{% if widget_data.show_header.value == 'Hide' %} padding-top: 40px;{% endif %} text-align: right; background-color: #FFFFFF; border-radius: 5px 5px 0px 0px;" valign="top"> <a href="{% text "secondary_website_link" label="Secondary Website Link", value="https://www.joyoushq.com", no_wrapper=True %}{% text "tracking_string" label="Tracking String", value="?utm_source=email&utm_channel=nurture&utm_campaign=customer_welcome", no_wrapper=True %}" style="text-align: center"> <img alt="" border="0" src="https://pulse.joyoushq.com/hubfs/images/logos/joyous-logo-black-400px.png?noresize" width="150" style="width:120px; margin: auto; margin-top: 4px; max-width: 80%; border-width: 0px; border-style: solid;" /> </a> </td>
  </tr>
  {% else %}
  <tr id="logo-header">
    <td align="center" class="bodyContent roboto-text" style="text-size-adjust: 100%; font-size: 14px; line-height: 15px; padding: 20px;{% if widget_data.show_header.value == 'Hide' %} padding-top: 40px;{% endif %} text-align: center; background-color: #FFFFFF; border-radius: 5px 5px 0px 0px;" valign="top"> <a href="{% text "main_website_link" label="Main Website Link", value="https://www.joyoushq.com", no_wrapper=True %}{{ widget_data.tracking_string.value }}" style="text-align: center"> <img alt="" border="0" src="https://pulse.joyoushq.com/hubfs/images/logos/joyous-logo-400px.png?noresize" width="200" style="width:200px; margin: auto; max-width: 80%; border-width: 0px; border-style: solid;" /> </a> </td>
  </tr>
  {% endif %}

I feel like I must be either doing somehting completely dumb or missing some subtlty in how I'm referencing the field, however can't spot anything in the docs, so hoping someone can point me in the right direction. Have tried the following:
- Setting a variable at the top of the template and referencing that instead
- Referencing via request_contact.contact.primary_subscription instead (same result, this is output to the template, but innaccessible in the if statement)

- Removed the other conditional statements inside the if statement, just in case adding one inside another was causing an issue for some reason - made no difference.

- Tried using single quotes or double quotes

- Tried using .value on the end

 

Any help/correction/magic ideas appreciated!

*For context: I do currently have this setup as a conditional section in the email (ie have made the header as a smart piece of content which is dependent on this field) , however, we're expanding our content library and also likely to add additional subscription branding options in the near future, so don't want to have to keep maintaining multiple options at an individual email level. Unless I've missed something having it coded at the template level is the best way of doing it?

1 Accepted solution

Accepted Solutions
BiG
Regular Contributor

Hi kaious

 

Sadly, if statements in HUBL are currently not implemented and not available for emails.

We went through the same journey as you did, but sadly for us, our problem cannot be solved by smart content, because it means differentiation on a too high level.

 

We would need the differentiation automatic and in the template, and not in the setup of each email. This because we send emails in 7 languages, and the workload for a weekly newsletter is immense, as you can guess.

 

So the optimal solution, which would also allow much more personalization in a much more effective and effizient way, is if we can use logic in our templates for emails.

 

Therefore, for everyone seing this: If you think it would be a great idea to have logic, created by if statements in email templates, please upvote this idea.
https://community.hubspot.com/t5/HubSpot-Ideas/if-statements-in-email-templates/idi-p/282907

3 Replies 3
Community Manager

Thanks for sharing @kaious


Did my post help answer your query? Help the Community by marking it as a solution
Reply
0 Upvotes
BiG
Regular Contributor

Hi kaious

 

Sadly, if statements in HUBL are currently not implemented and not available for emails.

We went through the same journey as you did, but sadly for us, our problem cannot be solved by smart content, because it means differentiation on a too high level.

 

We would need the differentiation automatic and in the template, and not in the setup of each email. This because we send emails in 7 languages, and the workload for a weekly newsletter is immense, as you can guess.

 

So the optimal solution, which would also allow much more personalization in a much more effective and effizient way, is if we can use logic in our templates for emails.

 

Therefore, for everyone seing this: If you think it would be a great idea to have logic, created by if statements in email templates, please upvote this idea.
https://community.hubspot.com/t5/HubSpot-Ideas/if-statements-in-email-templates/idi-p/282907

Regular Contributor

Wow, thanks for the response - I had no idea. We've been successfully using if statements with template module variables since day one, so just assumed that they'd work for prospect data. Definitely a big hole, and a really inconsistent implementation of the functionality - have upvoted your idea! Thanks for posting.

Reply
0 Upvotes