Found a post from a few years ago which stated:
“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.”
Does anybody know if this is still the case?
I’m attempting to use personalisation variables within if staements within an email template, and it’s currently failing - checking to see if this is the reason.
Thanks in advance
Hey, @EddBrisley
I found the documentation that quote is referencing and nothing has updated or changed. It still indicates the following — “Please note: if you’re using personalization tokens within a conditional statement of your email module, you must enable programmable email for the module.
Information passed via the transactional email API will not function within if statements, as the templates compile before the information populates.”
Best,
Jaycee
Hey, so just to check to see if I have this correctly. If I trigger a single-send email via API and use custom properties inside the payload then there’s no way for me to utilise these variables inside conditional statements @Jaycee_Lewis ?
Thanks in advance,
Jordan
Hi @JordanGG
I actually did find a hacky solution to this in the end.
Disclaimer: I would only suggest using it until the feature is improved as it’s *a tad* janky, and worked for my narrow use case
- maybe it’ll be helpful to you:
- initialise an array
- append different things to the array based on conditional statements
- profit
So for example:
{% set fruit = [] %}
{% if variable == “banana” %}
{% do fruit.append(“banana”) %}
//add whatever elif conditions you’d like
{% else %}
{% do fruit.append(" no fruit") % }
{% endif %}
Hope that helps 
Hey @EddBrisley,.
Thanks for your reply.
Can the variable be a customProperty? (Accounts Dashboard | HubSpot)
I tried putting these inside a condituion and it didn’t seem to work for me.
Any suggestions? I’d really like to get to step 3 (profit) 
{% if custom.associates_name == "Stuwart" %}
<h3>Hi Stu!</h3>
{% else %}
<h3>Oh hello {{custom.associates_name}}</h3>
{% endif %}
Ok, so we might have some candidates for what the issue is. In my implimentation I’ve got:
{% set fruit = [] %}
{% if contact.hubs_text_1 == “Banana” %}
{% do fruit.append(“Banana”) %}
{% elif contact.hubs_text_ == “Apple” %}
{% do fruit.append(“Apple”) %}
{% else %}
{% do fruit.append(“No fruit”) %}
{% endif %}
Then I’ll use a stripped out version of the fruit variable array within the text itself, and not directly the variable.
“Ah, there are so many {{ fruit }} growing this time of year”.
That way, I’m not *directly* using the custom variable. So! I’d do something like this:
{% set name = [] %}
{% if custom.associates_name == "Stuwart" %}
{% do name.append("Stuwart") %}
{% else %}
{% do name.append("There, buddy!") %}
{% endif %}
<h3> Hi {{ name }} </h3>
So basically we’re just taking the conditional logic and removing it a step by using an appended single entry length array instead (just remember to turn it into a string again after (take the square backets off)) 
Again, it’s limited and janky, and probably not the solution you’re looking for if you’ve got lots associates_names, but play around with it and maybe it’ll help.
The other thing it could be - I see you’re using properties from a custom object. Someone with more knowledge than me will be able to say if you can pull variables in HubL from custom objects or not, but you can sort of use custom variables as mentioned above.
again, sorry if this is of no help at all - hope you find a solution 