Removing apostrophe from contact owners name when being pulled into a HubL variable.

SOLVE
JonSasala1
Contributor

Hello,

 

We are using HubL to change the contact info displayed on our site in two ways. 

 

• First, if the visitor has a HubSpot owner, we display the owners  phone number.

• Second, if the HubSpot owner (rep) shared a link and includes a URL parameter of ?rep_first=jon&rep_last=smith, it displays Jon Smith’s information.

 

This is a simplified version of the code:

 

 

 

{% set rep_phone_jon_smith = “516-555-1111" %} {% set rep_phone_shane_oneil = “516-555-2222" %} 

{% if owner %} 
{% set rep_phone = "{{ rep_phone_"~owner.firstname~"_"~owner.lastname~"|default(‘888-555-1374') }}" %} 
<span>{{rep_phone}}</span> 
{% else %} 
{% set rep_phone = "{{ rep_phone_"~request.query_dict.rep_first~"_"~request.query_dict.rep_last~"|default(‘888-555-1374') }}" %} 
 <span>{{rep_phone}}</span>
{% endif %}

 

 

 

The first problem is this: Shane O’Neil has an apostrophe in his name, which throws off what is displayed when owner.lastname is pulled in.

 

Is there a way to remove an apostrophe from his name using code?

Using owner.lastname|cut(‘%27') does not seem to work.

 

 

Second small issue: the URL parameter reps are sharing are all lowercase, which I assume it should be and this works fine. The contact owner value, however, comes through Title Case, which makes the code not work. How can I force the contact owner value to be lowercase? 

 

 

Thanks for any help here.

 

0 Upvotes
1 Accepted solution

Accepted Solutions
ndwilliams3
Solution
Key Advisor

try this

owner.lastname|cut("'")|lower

lower is the filter you need to change case.

 

EDIT: fixed an issue with the code!

View solution in original post

0 Upvotes
3 Replies 3
JonSasala1
Contributor

I believe we just figured this out internally. Adding a \ before the apostrophe escapes it.

 

So owner.lastname|cut('\'') works for removing the apostrophe.

 

I would still be interested to find the best way to lowercase the Contact Owner value.

 

Thanks!

 

0 Upvotes
ndwilliams3
Key Advisor

Yes, escaping the apostrophe will work.

owner.lastname|cut('\'')

You can also use double quotes vs single quotes instead of escaping.

owner.lastname|cut("'")

 

0 Upvotes
ndwilliams3
Solution
Key Advisor

try this

owner.lastname|cut("'")|lower

lower is the filter you need to change case.

 

EDIT: fixed an issue with the code!

View solution in original post

0 Upvotes