using replace for first name on bad data

SOLVE
New Contributor

Greetings Hubl community! I'm new to the platform, just sort of learning on the fly. I've searched to no avail, but I have to figure there is a solution.

 

We are using {{contact.firstname}} for salutations both in the body content and Subject Lines. 

 

The problem is, some of the client data has initials for their first name entries. So the salutation would read "Dear C.," for example. The client doesn't like that.

 

Is there a way to search the strings and specify that there must be more than two characters in order to write out the name? Otherwise, the less than two characters gets the default option instead?

 

The client would prefer to use Valued Member over C. for instance. 

I'm still learning the syntax, so apologies if this is quite a newbie quesiton.

Thanks for your time and attention.
Best,

AC

1 Accepted solution

Accepted Solutions
Regular Contributor

Hello "Valued Member" (see what I did there... your name is only 2 characters).

 

The best (and only) way I can think of is to use a hubl {% if %} conditional in a template.

 

As far as I know, when using email tokens you are forced to set the default for when there isn't ANY value for that property... Less than ideal, I know.

 

If you have access to (and are comfortable using) templates, you can very easily accomplish this with the following statement.

{% set fname = contact.firstname|default('') %}
{% if fname|list|length > 2 %}
Dear {{contact.firstname}},
{% else %}
Dear Valued Member,
{% endif %}

This code sets the variable fname equal to a property of contact.firstname (make sure that's the right syntax for firstname). It also has a fallback of an empty string (in case there's no firstname property).

 

Then we usea list filter (breaks the string into each character) and the length filter (calculates the number of characters) wrapped in an "If statement" which checks if the length is greater than 2.

 

To actually add this into your email template, you'd want to select a HubL module from the drag-and-drop editor, bring it into the template above your email body section, then add the above code.customHublModule.png

 Once you've added the custom hubl module, add the chunk of code into it.customHublCode.png

 

 You may need to tinker with the position of the custom hubl module and you may also have to edit the CSS values of the module to match the padding / background of your email body, but this should accomplish what you're trying to do.

 

Best of luck!

- Mike

 

 

 

 

5 Replies 5
Regular Contributor

Hello "Valued Member" (see what I did there... your name is only 2 characters).

 

The best (and only) way I can think of is to use a hubl {% if %} conditional in a template.

 

As far as I know, when using email tokens you are forced to set the default for when there isn't ANY value for that property... Less than ideal, I know.

 

If you have access to (and are comfortable using) templates, you can very easily accomplish this with the following statement.

{% set fname = contact.firstname|default('') %}
{% if fname|list|length > 2 %}
Dear {{contact.firstname}},
{% else %}
Dear Valued Member,
{% endif %}

This code sets the variable fname equal to a property of contact.firstname (make sure that's the right syntax for firstname). It also has a fallback of an empty string (in case there's no firstname property).

 

Then we usea list filter (breaks the string into each character) and the length filter (calculates the number of characters) wrapped in an "If statement" which checks if the length is greater than 2.

 

To actually add this into your email template, you'd want to select a HubL module from the drag-and-drop editor, bring it into the template above your email body section, then add the above code.customHublModule.png

 Once you've added the custom hubl module, add the chunk of code into it.customHublCode.png

 

 You may need to tinker with the position of the custom hubl module and you may also have to edit the CSS values of the module to match the padding / background of your email body, but this should accomplish what you're trying to do.

 

Best of luck!

- Mike

 

 

 

 

New Contributor

Thank you Mike! I appreciate your time! My coworker showed me the disclaimer on this that a lot of the custom stuff wouldn't work on email -- only on blogs and landing pages. So I wasn't sure if this was just a waste of time to ask. 

 

I'll give it a shot, and let you know!


Thanks again Smiley Happy

Reply
0 Upvotes
Regular Advisor

If statements and filters do not work with contact properties in email templates. I wish it did as it would make my life easier! There are so many times that this would have solved a problem for me. Hopefully Hubspot will make this possible in the near future.

 

Reply
0 Upvotes
Regular Contributor

Now that you say that - I remember seeing that pretty explicitly in the docs while browsing... 

 

What about if you are filtering on the variable it's set to:

{% set fname = contact.firstname %}
{% if fname|list|length > 3 %}
{{contact.firstname}}
{% endif %}
Reply
0 Upvotes
Regular Advisor

Yeah, that was my thought too, but didn't work. I've found workarounds for other things, but this one has been a dead end.

Reply
0 Upvotes