CMS Development

mbattung
Member

IF Else Statement not working

SOLVE

I tried creating a module that will create a variable greeting. For instance if property “A” is filled it should show “A + First Name + Last Name” if property “A” is not filled it should show “Hello First Name”. I tried to do this using the examples on the IF/Else documentation but its not working 100% correctly. Below is my code, can you tell me what I am doing wrong?

 

{% if contact.to_the_parents_and_guardians_of %}
{{contact.to_the_parents_and_guardians_of}} {{contact.firstname}} {{contact.lastname}},
{% else %}
Hello {{contact.firstname}},
{% endif %}

0 Upvotes
1 Accepted solution
Bhargavi2503
Solution
Member

IF Else Statement not working

SOLVE

For using any Personalization Token in if/else condition, it is necessary to enable programmable email. And for that, you need to add isEnabledForEmailV3Rendering: true at the top of the template. For reference, please check the screenshot. For more, please go to this page.


enable-design-manager-template-for-programmable-email.png_width=765&name=enable-design-manager-template-for-programmable-email


View solution in original post

0 Upvotes
7 Replies 7
Bhargavi2503
Solution
Member

IF Else Statement not working

SOLVE

For using any Personalization Token in if/else condition, it is necessary to enable programmable email. And for that, you need to add isEnabledForEmailV3Rendering: true at the top of the template. For reference, please check the screenshot. For more, please go to this page.


enable-design-manager-template-for-programmable-email.png_width=765&name=enable-design-manager-template-for-programmable-email


0 Upvotes
Kevin-C
Recognized Expert | Partner
Recognized Expert | Partner

IF Else Statement not working

SOLVE

Hey @mbattung 

 

When you print the value and its possible option what do you see?

 

i.e:

{{ contact.to_the_parents_and_guardians_of  }}
Kevin Cornett - Sr. Solutions Architect @ BridgeRev
0 Upvotes
mbattung
Member

IF Else Statement not working

SOLVE

it give me "To the Parents or Guardians of" which is the set value for the property.

0 Upvotes
FabianRichter
Contributor

IF Else Statement not working

SOLVE

And what do you see, if it is empty? Try it with the suggested |pprint filter.

0 Upvotes
FabianRichter
Contributor

IF Else Statement not working

SOLVE

You could try it like that:

{% if contact.to_te_parents_and_guardians_of != "" %}
...
{% else %}
...
{% endif %}

Let me know if that works.

Fabian

mbattung
Member

IF Else Statement not working

SOLVE

thanks for your solution but that is not working for me either. For some reason the "else" portion gets ignored on your version and mine.

0 Upvotes
FabianRichter
Contributor

IF Else Statement not working

SOLVE

Then try to print out the empty value, maybe with:

{{ contact.to_the_parents_and_guardians_of|pprint  }}

 

Your "empty" value could also contain brackets like "[]". In this case you need to write it like that:

{% if contact.to_te_parents_and_guardians_of != "[]" %}
...
{% else %}
...
{% endif %}