CMS Development

kate4
Member

HubL if statement for custom contact properties

SOLVE

Hi!


I am creating a template for abandoned carts email. How do I output some html with custom contact properties only if those properties are not empty or zero?
My code:

{% if contact.abandoned_item_product_name_1 %}
    <table class="templateColumnWrapper" cellpadding="10">
    <tbody>
    <tr>
    <td class="column" style="vertical-align: middle;">
    <img src="{{ contact.abandoned_item_product_img_1 }}" width="130" style="max-width: 130px;">
    </td>
    <td class="column summary" style="vertical-align: top;">
    <div><b>{{ contact.abandoned_item_product_name_1 }}</b></div>
    <div>{{ contact.abandoned_item_product_price_1 }} {{contact.abandoned_base_currency}}</div>
    </td>
    </tr>
    </tbody>
    </table>
{% endif %}

This is the result:

kate4_0-1621355506910.png

 

 

 

0 Upvotes
1 Accepted solution
jonchim
Solution
Guide | Diamond Partner
Guide | Diamond Partner

HubL if statement for custom contact properties

SOLVE

Hey @kate4 yeahh 😞 I came across this regarding emails on this page https://developers.hubspot.com/docs/cms/hubl/if-statements\

 

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. 

Additionally, information passed via the Transactional Email API will not function within if statements, as the templates compile before the information populates. 






Jon Chim
VP of Design & Development
Hypha HubSpot Development


check Did my post help answer your query? Help the Community by marking it as a solution

View solution in original post

3 Replies 3
kate4
Member

HubL if statement for custom contact properties

SOLVE

Hi @jonchim !
It doesn't work for me(.  I found articles that the if statement was not supported for Contact Properties. For example, https://community.hubspot.com/t5/CMS-Development/Contact-Property-If-Statement-in-Email/td-p/1895 . Or this one https://community.hubspot.com/t5/HubSpot-Ideas/if-statements-in-email-templates/idi-p/282907
"if" statements don't work right now?

0 Upvotes
jonchim
Solution
Guide | Diamond Partner
Guide | Diamond Partner

HubL if statement for custom contact properties

SOLVE

Hey @kate4 yeahh 😞 I came across this regarding emails on this page https://developers.hubspot.com/docs/cms/hubl/if-statements\

 

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. 

Additionally, information passed via the Transactional Email API will not function within if statements, as the templates compile before the information populates. 






Jon Chim
VP of Design & Development
Hypha HubSpot Development


check Did my post help answer your query? Help the Community by marking it as a solution
jonchim
Guide | Diamond Partner
Guide | Diamond Partner

HubL if statement for custom contact properties

SOLVE

Hey @kate4,

 

I'm not entirely sure but try adding an if statment to wrap the product price and base currency, something like the below. I think this may work if the property is blank, not sure if it will work if it's filled in with a 0.

<div>
  {% if contact.abandoned_item_product_price_1 %}
    {{ contact.abandoned_item_product_price_1 }} {{contact.abandoned_base_currency}}
  {% endif %}
</div>

 






Jon Chim
VP of Design & Development
Hypha HubSpot Development


check Did my post help answer your query? Help the Community by marking it as a solution