CMS Development

andys2p
Participante

HubL using custom contact properties in if statements in an email template using Design Manager

resolver

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...

 

Any help is much appreciated.

 

Best regards,

Andy

 

Ps. I posted this issue on Email Marketing Tool forum, which might not be appropiate. An admin please delete that post. Thank you!

0 Avaliação positiva
1 Solução aceita
andys2p
Solução
Participante

HubL using custom contact properties in if statements in an email template using Design Manager

resolver

Hi Kevin,

 

Thank you for your reply!

 

I received an answer in the other thread opened here: https://community.hubspot.com/t5/Email-Marketing-Tool/HubL-using-custom-contact-properties-in-if-sta... (again sorry for the duplicate, if an admin can merge these two threads would be perfect).

 

I understand string comparison is case sensitive and that's what I expected too.

 

I tried your code like this:

{% set n_a = 'N/A' %}
{% set prop1 = contact.prop1 %} {# prop1 is 'N/A' #}
{% set prop2 = contact.prop2 %} {# prop2 is 'Something here' #}

Prop1: [{{ prop1 }}]
{% if prop1|upper != n_a %}
  <li>Prop1: [{{ prop1 }}]</li>
{% endif %}

Prop2: [{{ prop2 }}]
{% if prop2|upper != n_a %}
  <li>Prop2: {{ prop2 }}</li>
{% endif %}

and the result:

Prop1: [N/A]
  Prop1: [N/A]

Prop2: [Something here]
  Prop2: [Something here]

so basically if statements are not supported yet in email templates, but only in CMS and Blog pages.

 

Anyone having this issues please upvote these ideas (as @MatthewShepherd mentioned in the other thread):

 

https://community.hubspot.com/t5/HubSpot-Ideas/if-statements-in-email-templates/idi-p/282907

 

https://community.hubspot.com/t5/HubSpot-Ideas/If-Statements-in-HubL-for-Email-Templates/idi-p/21678...

 

Thank you!

Exibir solução no post original

2 Respostas 2
Kevin-C
Especialista reconhecido(a) | Parceiro
Especialista reconhecido(a) | Parceiro

HubL using custom contact properties in if statements in an email template using Design Manager

resolver

Hey @andys2p 

 

So comparing strings get awkward really fast.

For starters comparing strings is case sensitive, and this could be your issue.

Usually you'd want to help avoid human error by converting the case to ensure it's truly the value you're comparing.

 

To remedy try something like:

{% set prop1 = contact.prop1 %}

{% if prop1|upper != 'N/A'%}
  Property 1 is valid: [{{ contact.prop1 }}]
{% endif %}

 

If you continue to see issue please reach out!

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
0 Avaliação positiva
andys2p
Solução
Participante

HubL using custom contact properties in if statements in an email template using Design Manager

resolver

Hi Kevin,

 

Thank you for your reply!

 

I received an answer in the other thread opened here: https://community.hubspot.com/t5/Email-Marketing-Tool/HubL-using-custom-contact-properties-in-if-sta... (again sorry for the duplicate, if an admin can merge these two threads would be perfect).

 

I understand string comparison is case sensitive and that's what I expected too.

 

I tried your code like this:

{% set n_a = 'N/A' %}
{% set prop1 = contact.prop1 %} {# prop1 is 'N/A' #}
{% set prop2 = contact.prop2 %} {# prop2 is 'Something here' #}

Prop1: [{{ prop1 }}]
{% if prop1|upper != n_a %}
  <li>Prop1: [{{ prop1 }}]</li>
{% endif %}

Prop2: [{{ prop2 }}]
{% if prop2|upper != n_a %}
  <li>Prop2: {{ prop2 }}</li>
{% endif %}

and the result:

Prop1: [N/A]
  Prop1: [N/A]

Prop2: [Something here]
  Prop2: [Something here]

so basically if statements are not supported yet in email templates, but only in CMS and Blog pages.

 

Anyone having this issues please upvote these ideas (as @MatthewShepherd mentioned in the other thread):

 

https://community.hubspot.com/t5/HubSpot-Ideas/if-statements-in-email-templates/idi-p/282907

 

https://community.hubspot.com/t5/HubSpot-Ideas/If-Statements-in-HubL-for-Email-Templates/idi-p/21678...

 

Thank you!