CMS Development

DavidFJones
Member | Platinum Partner
Member | Platinum Partner

Compare personalization_token value

SOLVE

Hey all,

I'm trying to check if a value/property exists using a personalization token. I need to use the token as the value I am checking needs to be dynamic and change per each page.

Currently this is what my code looks like

{% set lessonID = "1234" %}
{% set testvalu = personalization_token("contact."~lessonID,"null") %}
{% if testvalu == 'null' %}
  This checked worked
{% endif %}

The problem is that if  the contact property "contact.1234" is not set, then this if statement is not firing.

I have also tried setting a third value in between the testvalu and if statement

{% set lessonID = "firstname" %}
{% set testvalu = personalization_token("contact."~lessonID,"null") %}
{% set thirdTest = testvalu %}
{% if thirdTest == 'null' %}
  This checked worked
{% endif %}

but this still does not work. I can also confirm that "null" is being set, if I check either {{testvalu}} or {{thirdTest}}, null will be printed on the screen in this instance.

The only other thing to add is I have tried using both single and double quotes when checking my null string value == "null" or == 'null' .

Thank you

0 Upvotes
1 Accepted solution
DavidFJones
Solution
Member | Platinum Partner
Member | Platinum Partner

Compare personalization_token value

SOLVE

So I found that if I used pprint on a personalization token that it wasn't actually just printing a string, it was printing a long list of characters/variables that made it unable to be compared to anything else.

The solution was to instead call the property using square brackets. so

{% set testValu = contact["lesson1234"] %}

Using this now testValu can be compared to anything else like a normal variable


View solution in original post

2 Replies 2
alyssamwilie
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

Compare personalization_token value

SOLVE

Hey @DavidFJones 

Usually you can just do

{% if not testvalu %} {% endif %}

or

{% unless testvalu %} {% endunless %}

to check if a value doesn't exist.

Eiher of these work for you?

If this answer solved your question, please mark it as the solution.

Alyssa Wilie Profile Image

Alyssa Wilie

Web Developerat Lynton

Learn HubL | Get Marketing Insights

HubSpot Elite Solutions Partner
Lynton's HubSpot theme Rubric now available. Click to download.
DavidFJones
Solution
Member | Platinum Partner
Member | Platinum Partner

Compare personalization_token value

SOLVE

So I found that if I used pprint on a personalization token that it wasn't actually just printing a string, it was printing a long list of characters/variables that made it unable to be compared to anything else.

The solution was to instead call the property using square brackets. so

{% set testValu = contact["lesson1234"] %}

Using this now testValu can be compared to anything else like a normal variable