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