Space in personalization token when no value is present

Hi,

I want to create a personalization module that inserts the firstname where there is a value and does nothing when there isn’t.

So…

“Hi Jonathan,” or “Hi,”

If there is no value with regular personalization the space is still there because it is written as “Hi[space][Firstname],”.

I tried creating a module with the following code:

{% if contact.firstname %}Hi {{ contact.firstname }},{% else %}Hi,{% endif %}

But I am still getting the default value for the firstname field - “Hi there,”.

Any suggestions on how to do this?

Thanks,

Jonathan

Hi, @JCrowNM :waving_hand: Thanks for your question. Did you get things moving forward?

I created a simple module and got a step closer. But I cannot get the space to not render in my else statement. Here’s my HubL so far:

{% if contact.firstname and contact.firstname != "there" %}
 Hi {{ contact.firstname }},
{% else %}
 Hi,
{% endif %}

Maybe you can get it over the finish line from here?

Talk soon! — Jaycee

Thanks Jaycee.

Great idea. Unfortunately still not working for me, I believe because the default value for when there is no first name is “there”. So it is still saying “Hi there,”. My assumption is because the value for contact.firstname is still blank. I guess I need to find a way to override the default value or just make the default value blank. I would just then need to make sure every email has specific values in any personalization tokens for the subject or preview text.

Anyone have any idea how to overwrite the default value though? That would be ideal.