How to hide a TR based on a module variable containing a token

Jopitts
Member

All,

I'm trying to work out what dumb thing I'm doing here.

 

I have the following code in my table:

{% if module.job_title != "hide" %}
                          <tr>
                            <td style="color:inherit; font-family:inherit; ">
                              {% inline_text field="job_title" value="{{ module.job_title }}" %}
                            </td>
                          </tr>
                          {% endif %}
                          

I have a variable defined in my module (job_title) which by default contains the following:

{{ personalization_token('contact.hubspot_owner_id.hs_job_title', 'hide') }}

However, I am getting the row showing up with the word 'hide' in it.

 

How can I hide the TR based on the value of the variable, when the variable contains a personalisation token?

0 Upvotes
2 Accepted solutions
Christensen
Solution
Contributor

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.

View solution in original post

0 Upvotes
Jopitts
Solution
Member

@Christensen , turns out that turning on the programmable email option solved things.  It radically changed the way HUBL interpreted object properties.

 

Thanks for the help!!  It's much appreciated

 

Cheers

Jo

View solution in original post

14 Replies 14
Jopitts
Member

@BérangèreL , any thought on any other experts who could weigh in?  This can't be that hard of a question for someone to help out with.

0 Upvotes
BérangèreL
Community Manager
Community Manager

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





loop


Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.

Learn More




0 Upvotes
Jopitts
Member

All,

FWIW - Have tried this variant with no luck.

 

I have this code in my module:

 {% if module.job_title != 'OWNER.HS_JOB_TITLE' %}
                          <tr>
                            <td style="color:inherit; font-family:inherit; ">
                              {{ module.job_title }}
                            </td>
                          </tr>
                          {% endif %}

And for the job_title variable, I have now just set it to:

{{ contact.hubspot_owner_id.hs_job_title }}

 

I still see the row, only with 'OWNER.HS_JOB_TITLE' in it.

 

Cheers

Jo

0 Upvotes
BérangèreL
Community Manager
Community Manager

Hi @Jopitts and Happy Friday! 🙌
 

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





loop


Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.

Learn More




0 Upvotes
Jopitts
Member

@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.

 

Cheers

Jo

0 Upvotes
Jopitts
Member

All,

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:

{% set showRow = personalization_token('contact.hubspot_owner_id.hs_main_phone', 'hide')  %}
                          {% if showRow != "hide" %}
                          <tr>
                            <td style="color:inherit; font-family:inherit; ">
                              <span style="font-weight:700">P&nbsp;</span>
                              <a style="text-decoration:none; color:inherit; font-family:inherit; " href="tel:{{ contact.hubspot_owner_id.hs_main_phone }}">{{ contact.hubspot_owner_id.hs_main_phone }}</a>
                              <span>showRow: {{showRow}}</span>
                            </td>
                          </tr>
                          {% endif %}

 And this is my output

Jopitts_0-1764357811116.png

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?

 

Cheers

Jo

0 Upvotes
Christensen
Contributor

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  %}

 

0 Upvotes
Jopitts
Member

@Christensen , I've extended my code a little further in the hunt for answers.  This is the current state:

                          {% set showRow = personalization_token('contact.hubspot_owner_id.hs_main_phone', 'hide')|string  %}
                          {% if showRow != 'hide' %}
                          <tr>
                            <td style="color:inherit; font-family:inherit; ">
                              <span style="font-weight:700">P&nbsp;</span>
                              <a style="text-decoration:none; color:inherit; font-family:inherit; " href="tel:{{ showRow }}">{{ showRow }}</a>
                              <p>
                                Data on showRow: {{ showRow|pprint }}
                              </p>
                            </td>
                          </tr>
                          {% endif %}

 

This is the current output:

 hide

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. 

 

Thoughts?

0 Upvotes
Jopitts
Member

@Christensen , I'd already tried that.  Still no luck.  This code snippet in it's current state:

{% set showRow = personalization_token('contact.hubspot_owner_id.hs_main_phone', 'hide')|string  %}
                          {% if showRow != 'hide' %}
                          <tr>
                            <td style="color:inherit; font-family:inherit; ">
                              <span style="font-weight:700">P&nbsp;</span>
                              <a style="text-decoration:none; color:inherit; font-family:inherit; " href="tel:{{ showRow }}">{{ showRow }}</a>
                            </td>
                          </tr>
                          {% endif %}

Any other thoughts?

Cheers

Jo

0 Upvotes
Jopitts
Member

@Christensen , 

More updates.  It turns out, my lack of knowledge meant I wasn't pulling the contact data correctly (and I may still not be).

 

My code now looks like this:

{% set showRow = contact_owner.additional_phone|replace(" ", "") %}
                          {% if showRow && showRow != '' %}
                          <tr>
                            <td style="color:inherit; font-family:inherit; ">
                              <span style="font-weight:700">C&nbsp;</span>
                              <a style="text-decoration:none; color:inherit; font-family:inherit; " href="tel:{{ showRow }}">||{{ showRow }}||</a>
                              length: {{ showRow|length }}
                            </td>
                          </tr>
                          {% endif %}

The output looks like this:

 |||| length: 26

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.  

 

0 Upvotes
Christensen
Solution
Contributor

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.

0 Upvotes
Jopitts
Solution
Member

@Christensen , turns out that turning on the programmable email option solved things.  It radically changed the way HUBL interpreted object properties.

 

Thanks for the help!!  It's much appreciated

 

Cheers

Jo

BérangèreL
Community Manager
Community Manager

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





loop


Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.

Learn More




0 Upvotes
Jopitts
Member

@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.

 

Cheers

Jo

0 Upvotes