Skip to main content

Can I use the "Case Statement" in Email?

I am trying to personalize the greeting in emails, and we need the prefix for a contact to show-up in the greeting. Since I cannot use the prefix function in NB, we have created a new custom field. In this custom field, we have included prefixes for contacts in different level of government. 

I know that for emails I can use the {%if %} and {%else%} options to say that if this contact contains a field with "Ms." then say Hello Ms. Joe, if not to say Hello Allan. BUT can I add more conditions can I use {% case%} for this?

For only two criteria I can use this code:

{% if recipient.custom_values_for_display['prefix'] contains "Ms." %}

Dear {{ recipient.custom_values_for_display['prefix'] }} --

{% else%}

Dear {{ recipient.first_name_or_friend }} -- 

{% endif %}

 

But I need to include Mr., MPP, Mayor etc. Is there a way to use the {%case%} code?

Official response from

Hi Andreea,

While you should be able to use "Case" even in email blasts, there are a few easier ways to do this. The easiest is to check whether or not that field is empty and display your default content if it is and your custom field if it's not. Like so:



{% if recipient.custom_values_for_display['prefix'] == blank %}

Dear  {{ recipient.first_name_or_friend }} --

{% else %}
Dear {{ recipient.custom_values_for_display['prefix'] }}  {{ recipient.last_name }} --

{% endif %}

 


It is also worth noting, for other use cases, that you can use the {% elsif %} tag to add alternative if statements, like so:

 



{% if recipient.custom_values_for_display['prefix'] contains "Ms." %}

something

{% elsif recipient.custom_values_for_display['prefix'] contains "Mr." %}

something else

{% elsif recipient.custom_values_for_display['prefix'] contains "Dr."%}

something different

{% else %}

this is what shows if it doesn't conatain any of those

{% endif %}

Share this post

Showing 1 reaction

How would you tag this suggestion?
Please check your e-mail for a link to activate your account.