If you’ve tried using the out-of-the-box solution for adding First Name personalisation code to your klaviyo emails, you may have come across the following little problem: you don’t want to have to specify a fallback value, but if you don’t, you’re left with an extra space before the comma.
The problem
Hey {{ first_name|default:'there' }},
The above will display “Hey Janet,” if a first name exists, or “Hey ,” if it doesn’t. That leaves us with an extra space before the comma and makes us look terrible at writing copy. Don’t worry – I came across the same issue and have a simple solution.
The solution
To give us more control, we can use the following “if” statement:
{% if person.first_name %}
<div>Hi {{ first_name|title }},</div>
{% else %}
<div>Hi,</div>
{% endif %}
The above tells Klaviyo to check if the user has a value in the “First name” field of their profile. If they do, it’ll show their first name; if they don’t, it’ll display “Hi,” – that’s our extra space sorted. The “title” bit after “first_name” tells Klaviyo to make sure the name is displayed in Title case (you’d be surprised how many people don’t bother to capitalise their own name when signing up).
Select code view ( </> ) in a text box in the klaviyo editor, then paste in the “if” statement from above. You can test that it’s working correctly by clicking Preview & test. You’ll see the view as per the user that’s currently displayed in the sidebar.
If you want to test the view for someone who has/hasn’t got a first name assigned, try opening a new browser tab and adding yourself to the mailing list. Add/remove your first name from your profile, then hit Search for a Profile to find your profile by email address or name.