If statement to check if personalization token is empty

Hello,

I am creating a module in which i want to check if my personalization token is empty.

personalization token is {{personalization_token(“contact.firstname”, " ")}} .
If personalization token has value, i want to display " Hello, {{personalization_token(“contact.firstname”, " “)}}”

If the personalization token is empty, i want to display a new html text section.
So far i have this code, would appreciate some help on where i need to modify it for it to work.

{% set Value = personalization_token(“contact.firstname”,“Null”) %}
{% set NewValue = Value %}

{% if NewValue == “Null” %}
<p>
Glad to have you with us!
</p>

{% elif %}

<p>
Hello, {{personalization_token(‘contact.firstname’, ’ ') }}
</p>

{% endif %}

Hello @ChrisChiha,

try this!

{% unless contact.firstname =="" %}
{{ contact.firstname }}
{% else %}
HTML
{% endunless %}

best regards

Özcan

I tried it.

It is showing contact name in both cases.
If there’s value it is showing the name, if it is empty it is showing blank space. Thoughts ?

Hi @ChrisChiha,

Were you able to find a solution? I hqve been trying to use if statement to hide table content when personalization token value is empty. Please let me know, if you were able to find a solution. TIA!

Hello @SIllath ,
Yes it worked.

I am using this code to display/hide content when personalization token is empty:

{% unless deal.customer_full_name ==“” %}
<!-- Section applicable if personalization token is not empty -->

{% else %}
<!-- Section applicable if personalization token is empty -->

{% endunless %}

Hi@ChrisChiha,

Thank you so much for your response. Is there anything different in the above conditional statement, if we have a custom object?

Thanks!

Will the HTML from my code be diplayed when firstname is missing?

Have you inserted your function/text which should be displayed as fallback?

The blank space is an indicator for missing informations/data.

Have you entered a default value for your fallback? Like your welcome message.

best regards

Özcan

I used this, When there’s value it displayed : Hey, Value
When it is empty, it displayed : Hey,

{% unless contact.firstname =="" %}
Hey, {{ contact.firstname }}
{% else %}
Empty
{% endunless %}

Are you looking/testing it in the preview of the page/email? Because, unless u select proper contact for preview it will be displayed either as CONTACT.FIRSTNAME or “blank”.

Also I would recomend to get the personalition token right by openning an richtext function selecting the right token and copy it from the source code.

Best

Özcan

Yes, i am following the above steps. Tried different approaches, i am losing hope.

Is there any other way top specify if a value is null other than ==“” ?

Have you selected a contact for preview?

You can modify the code to:

{% if contact.firstname !="" %}
HTML
{% else %}
{{ contact.firstname }}
{% endif %}

Best

Özcan

Yes that’s where i am choosing contacts.
For this code, i am having HTML displayed whenever i choose any contact (whether the first name has value or not). Just to be clear, i created a module and i am executing this code inside it

{% if contact.firstname !="" %}
HTML
{% else %}
{{ contact.firstname }}
{% endif %}

Is there something else in the module?

It finally worked, had some isues with my hubspot session.
Cheers !