Thank you so much for reaching out to the HubSpot Community and for sharing the code you used.
I’ve gathered some helpful resources on this topic for you:
- HubL filters
- If statements
- HubL functions
Let’s also check in with our wonderful Top Experts: Hi @Anton, @sylvain_tirreau and @SteveHTM do you have any suggestions or tips to help @Jopitts, please?
Thank you all for your support, and wishing everyone a fantastic weekend!
Bérangère
@BérangèreL , thanks for replying. There is a lot of interesting info in those links and I really appreciate you sending them through, but nothing in there gets me over the line sadly.
Hopefully I’ll get something back from one of the experts.
I’ve further simplified things, but with no better outcome. I’m no longer using a module variable, just embedding the personalisation token directly into my code:
Given the if statement should only allow this to be displayed when the value of showRow is not hide, why on earth is it showing it when the value of showRow clearly IS hide?
Hey @Jopitts , I think the issue is that personalization_token() isn’t outputting a plain string, while your comparison is checking against a literal string “hide”. This type mismatch would explain why the condition evaluates incorrectly even though it displays as “hide”.
Try adding the |string filter to convert the token output to a comparable string:
{% set showRow = personalization_token('contact.hubspot_owner_id.hs_main_phone', 'hide')|string %}
why is the length showing as 26? And if the length is 26, how are there no gaps between the || symbols I’ve prefixed and suffixed the output with?
Where are the HUBL experts?
I must be doing something very silly, and it seems no one in the community can tell me what, which is astounding beyond belief.
Hey @Jopitts , I was so sure that I replied to you but it looks like I missed my opportunity to send my last
Anyway, this happens because it’s counting the characters from the object that was returned from contact_owner.additional_phone|replace(" ", “”). What you need is the actual value of a property to make the comparison.
Upon digging around and testing HubL in the email editor, it looks like that you can’t use the personalization_token for comparison because it loads AFTER the HubL logic therefore the long length.
As a workaround, you can create a HubSpot email module with programmable email turned on for this then use the direct reference to the property without the personalization_token function which will render the value before the HubL logic.
I also don’t think the contact_owner.additional_phone is a valid property reference nor contact.hubspot_owner_id.hs_main_phone but I know that contact.hubspot_owner_id.firstname and contact.hubspot_owner_id.lastname is a valid property references.
This is now beyond an email personalization and would fall in the custom email module development work.
@Christensen , this is a custom email module. It contains HTML and HUBL.
I’m not using the personalisation token approach, but just the direct contact properties (you can see from the code that I am going direct to contact_owner.<property> rather than the personalization approach).
I will try turning the programmable email on regardless, and let you know the outcome.
Great to hear, @Jopitts! Thanks for sharing your solution, this will be helpful to others.
If you have more questions, feel free to ask!
Have a lovely day!
Bérangère
Data on showRow: (String: {“objectExpression”:“contact_without_defaults.hubspot_owner_id.hs_main_phone”,“defaultExpression”:“contact.hubspot_owner_id.hs_main_phone”,“localDefault”:“hide”})
I was surprised by this as it indicates that showRow is still not being seen as a string.
Hi @Jopitts and thanks for getting back to us!
Please note that our forum is a peer-to-peer support forum and all of our members are volunteers.
The issue here seems to be with the personalization_token() that returns the actual value when the contact is known, not the default “hide” string.
Could you please check if the value is empty or equals the default instead or use an empty string check to see if that helps.
Here is a documentation that might help: “HubL functions”.
Now let’s consult with our Top Experts: Hi @tmcginnis, @Christensen and @RubenBurdin can you think of other suggestions to help @Jopitts, please?
Thanks so much for your help and have a lovely day!
Bérangère