I have created a custom email module, with the following code
<p>Dear {% if contact.firstname != "" and contact.lastname != "" %}{{contact.firstname}} {{contact.lastname}}{% else %}Mr./Mrs{% endif %},</p>
I also changed on of our contacts to have an empty lastname
But when i send a test mail using that contact’s info the if statement doesnt seen the lastname as being an empty string. end it just prints the values eventhough lastname is empty.
Could this be a problem with the test email option? or am i missing something?
Are you able to confirm that the empty lastname property is seen an empty string? If it’s a null value, or anything other than an empty string, that statement will still register as TRUE.
Can you try to change your if statement to look more like contact.lastname.value instead of contact.lastname != “” and see what that does for you?
The lastname value for this contact should be empty.
I removed any value from its field on the edit contact page.
I tried contact.lastname.value, but that doesnt make any difference! It also doesnt print anything. contact.firstname.value also has no value. So i dont think value is a value on this object!
Is there anyway i can check what contact.lastname actualy returns?
I found this community post from April where they are using ‘none’ instead of an empty string. Can you try that to see if it works?
If pprint is showing that, it’s identifying it as a string, so I’m wondering if Hubspot uses some default null value. I’m having a hard time finding documentation that speaks to this.
<p>Dear {% if contact.firstname.value is none or contact.lastname.value is none %}Mr./Mrs{% else %}{{contact.firstname}} {{contact.lastname}}{% endif %},</p>
and
<p>Dear {% if contact.firstname is none or contact.lastname is none %}Mr./Mrs{% else %}{{contact.firstname}} {{contact.lastname}}{% endif %},</p>
and
<p>Dear {% if contact.firstname is blank or contact.lastname is blank %}Mr./Mrs{% else %}{{contact.firstname}} {{contact.lastname}}{% endif %},</p>
All of them dont work!
Thanks again for trying to help! i;m goiung to keep hacking at this!
If you come up with any more suggestions please let me know!
Just to let you know, i tried it with both this setting on and off! It makes no difference.
So i gave up.
The workaround im using right now is updating all contacts with a salutation field where i combine the first and last names using a script, and adding Mr/Mrs to the field where the names are empty.