# if statement on custom properties in Email

**URL:** <https://community.hubspot.com/t/if-statement-on-custom-properties-in-email/10164>\
**Category:** CMS Development\
**Created:** [September 12, 2018, 9:20am UTC](https://community.hubspot.com/t/if-statement-on-custom-properties-in-email/10164 "2018-09-12T09:20:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![blowltd](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/blowltd/32/52876_2.png) [@blowltd](https://community.hubspot.com/u/blowltd)\
**Post date:** [September 12, 2018, 9:20am UTC](https://community.hubspot.com/t/if-statement-on-custom-properties-in-email/10164/1 "2018-09-12T09:20:00Z")

</div>

Hi,

I am trying to send a transactional email with Hubspot.

This email is HTML+Hubl and for some reason my If statement is not working as expected.

So we are sending a custom.properties sometimes with content to render and sometimes not.

so first I thought: Let’s try to check if this property “is defined”,

unfortunately, the API make mandatory to receive this custom property so “is defined” does not work.

Then I thought let’s always send something but when I have no content, set this property to “null” or false or a string.

Then I tried to test if my property is one of those and it is not working…

I am lost, does someone has any idea?

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [September 12, 2018, 9:27am UTC](https://community.hubspot.com/t/if-statement-on-custom-properties-in-email/10164/2 "2018-09-12T09:27:55Z")

</div>

Hi @blowltd,  
I’ve used HubL properties several times in my emails.  
Everytime there is a property and I need to do conditional, I just use,

`{% if variable_name %}show your content{% endif %}`

I use it the above way when I am using Custom Modules for my Email.  
If I want to use normal HubL variables,

```auto
For Rich Text,

{% rich_text "my_module" label='My rich text module', html='Default module text' %}
{% if "my_module" %}
A module named "my_module" is defined in this template.
{% endif %}

For text fields,

{% text "product_names" label='Enter the product names that you would like to render the coupon ad for', value='all of our products', export_to_template_context=True %}

{% if widget_data.product_names.value %}
<div class="coupon-ad">
<h3>For a limited time, get 50% off {{ widget_data.product_names.value}}! </h3>
</div>
{% endif %}

For choice fields,

{% choice "department" label='Choose department', value='Marketing', choices='Marketing, Sales, Dev, Services' export_to_template_context=True %}

{% if widget_data.department.value == 'Marketing' %}

<h3>Want to join our amazing Marketing team?!</h3>
<h4>We have exciting career opportunities on the {{ widget_data.department.value }} team.</h4>

{% elif widget_data.department.value == 'Sales' %}

<h3>Are you a Sales superstar?</h3>
<h4>We have exciting career opportunities on the {{ widget_data.department.value }} team.</h4> 

{% elif widget_data.department.value == 'Dev' %}

<h3>Do you love to ship code?</h3>
<h4>We have exciting career opportunities on the {{ widget_data.department.value }} team.</h4>

{% else %}

<h3>Want to work with our awesome customers?</h3>
<h4>We have exciting career opportunities on the {{ widget_data.department.value }} team.</h4>

{% endif %} 

For Checkbox / Boolean,

{% boolean "check_box" label='Show alert', value=True, export_to_template_context=True %}

{% if widget_data.check_box.value is truthy %}
<div class='alert'>Danger!</div>
{% endif %}

```

Let me know if it helps…

---

<div class="post-metadata">

**Author:** ![blowltd](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/blowltd/32/52876_2.png) [@blowltd](https://community.hubspot.com/u/blowltd)\
**Post date:** [September 12, 2018, 9:31am UTC](https://community.hubspot.com/t/if-statement-on-custom-properties-in-email/10164/3 "2018-09-12T09:31:38Z")

</div>

Hi,

I did try the first one:

```auto
{% if custom.my_variable %}
<p> Hello </p>
{% endif %}

```

but when I send without this “custom.my\_variable” to the API

The error I got from the API is:

`Mismatch in custom properties between template and request.\n - Custom properties in the template, but not in the request:`

So clearly I can’t do this test as API refuses not to send the property.

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [September 12, 2018, 9:41am UTC](https://community.hubspot.com/t/if-statement-on-custom-properties-in-email/10164/4 "2018-09-12T09:41:41Z")

</div>

@blowltd Can you share your HubL Code declaring the variable?

---

<div class="post-metadata">

**Author:** ![blowltd](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/blowltd/32/52876_2.png) [@blowltd](https://community.hubspot.com/u/blowltd)\
**Post date:** [September 12, 2018, 9:43am UTC](https://community.hubspot.com/t/if-statement-on-custom-properties-in-email/10164/5 "2018-09-12T09:43:30Z")

</div>

Hi,

here is the declaration:

```auto
{% if custom.get_ready_3 %}
 <table align="left" border="0" cellpadding="0" cellspacing="0" style="max-width:300px;" width="100%" class="mcnTextContentContainer">
 <tbody>
 <tr>
 <td valign="top" class="mcnTextContent" style="padding-top:0; padding-left:18px; padding-bottom:9px; padding-right:18px;">
 <div style="text-align: center;"><img data-file-id="38533" height="50" src="https://img.blowltd.com/transactional/4.png" style="border: 0px initial ; width: 50px; height: 50px; margin: 0px;" width="50"><br>
 <br>
 <span style="font-size:15px"><span style="font-family:roboto,helvetica neue,helvetica,arial,sans-serif">{{ custom.get_ready_3 }}</span></span><br>
 </div>
 </td>
 </tr>
 </tbody></table>
 {% endif %} 

```

---

<div class="post-metadata">

**Author:** ![kincorvia](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kincorvia/32/18373_2.png) [@kincorvia](https://community.hubspot.com/u/kincorvia)\
**Post date:** [March 25, 2019, 11:21pm UTC](https://community.hubspot.com/t/if-statement-on-custom-properties-in-email/10164/6 "2019-03-25T23:21:45Z")

</div>

I have the same issue, did you ever resolve this? The accepted answer does not seem relevant to the issues we are facing with transactional emails using the single send API.

---

<div class="post-metadata">

**Author:** ![BiG](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/big/32/78471_2.png) [@BiG](https://community.hubspot.com/u/BiG)\
**Post date:** [July 26, 2019, 11:50am UTC](https://community.hubspot.com/t/if-statement-on-custom-properties-in-email/10164/7 "2019-07-26T11:50:55Z")

</div>

I agree.

This is not a real solution to me.

I have the same issue.  
See also:

[https://community.hubspot.com/t5/CMS-Development/if-statements-in-email-templates/m-p/282907](https://community.hubspot.com/t5/CMS-Development/if-statements-in-email-templates/m-p/282907)

Please support this idea which queries for if statements in HUBL for emails:  
[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-email-templates/idi-p/282907)
