HubL using custom contact properties in if statements in an email template using Design Manager
SOLVE
Hello,
I want to use an email template for an email which will be used in a workflow. I created the template using Design Manager.
In contacts I defined prop1 and prop2 properties which are "Single-line text" type. prop1 and prop2 are updated using API calls from our platform and in case these are invalid or not yet set in our platform, I update them with 'N/A' value.
In email template I want to show a specific text for prop1 only if prop1 is not 'N/A' and another text if prop2 is not 'N/A'. To achieve this I added following code in email template:
PROP1: [{{ contact.prop1 }}]
{% if contact.prop1 != 'N/A' %}
Property 1 is valid: [{{ contact.prop1 }}]
{% endif %}
PROP2: [{{ contact.prop2 }}]
{% if contact.prop2 != 'N/A' %}
Property 2 is valid: [{{ contact.prop2 }}]
{% endif %}
When I edit the email which uses above email template and go to "Preview", choose a contact which has prop1 set to 'N/A' (without quotes) and prop2 set to 'Something here', the result in the preview is:
PROP1: [N/A]
Property 1 is valid: [N/A]
PROP2: [Something here]
Property 2 is valid: [Something here]
I searched other issues related to my problem, I tried using contact.prop1.value, contact.prop1|string != 'N/A'|string to be sure is not something related to prop1 type. Nothing works...
"Please note that using personalization variables (contact and company variables) within if statements is not currently supported for email in HubSpot. These variables can be used for logic on HubSpot CMS pages and blog templates."
Could you perhaps achieve what you are looking for by putting contacts in Contact Lists based on their contact record prop1 and prop2 values and then use Smart Content in your emails to show different content blocks to your different contact lists?
Matthew Shepherd
Freelance HubSpot Consultant CRM Consultant | SEO Specialist
"Please note that using personalization variables (contact and company variables) within if statements is not currently supported for email in HubSpot. These variables can be used for logic on HubSpot CMS pages and blog templates."
Could you perhaps achieve what you are looking for by putting contacts in Contact Lists based on their contact record prop1 and prop2 values and then use Smart Content in your emails to show different content blocks to your different contact lists?
Matthew Shepherd
Freelance HubSpot Consultant CRM Consultant | SEO Specialist
HubL using custom contact properties in if statements in an email template using Design Manager
SOLVE
Hi Matthew,
Thank you for your quick response.
I see what you mean, but we cannot do lists based on property values as we have lots of values set for each contact individually and there should be lots of if's in the template.
Do you know if there is in backlog to add this functionality to email templates, and if yes, when would this be available?
As quick solution for whoever wants to implement same functionality, I think we would create the blocks of HTML to embed in email template (using contact properties) in our framework and we will update the properties with HTML code already formatted and in email template we would just put {{ prop1 }}{{ prop2 }}...{{ propX }}.