Hi!
I got an content snippet in D365 Marketing in which I regulate the correct salutation. Here below is the code:
{{#if (eq contact.gendercode 1)}}
Sehr geehrter Herr {{contact.bbg_amtstitel}} {{contact.bbg_akadtitelprefix}} {{contact.lastname}} {{contact.bbg_akadtitelpostfix}},
{{else if (eq contact.gendercode 2)}}
Sehr geehrte Frau {{contact.bbg_amtstitel}} {{contact.bbg_akadtitelprefix}} {{contact.lastname}} {{contact.bbg_akadtitelpostfix}},
{{else}}
Sehr geehrte Damen und Herren,
{{/if}}
this works perfectly fine, yet if the person got no title postfix, the e-mail is displayed with a whitespace. I read the documentation about the white space control but I am not sure how to apply it on my liquid code since it differs.
Here is a screenshot of the salutation with the space:
Thanks!
Hey Nya,
as explained by you the {{else}} Statement does not work, yet the other code provided by you works perfectly fine.
I just wanted to ask you if you could explain a bit more how to achieve the {{else}} Statement to work.
Thanks!
Hi,
If the issue has been solved, it would be appreciated if you could click "Yes" to verify my answer.
If there is any further doubt, please do not hesitate to let me know.
Hi,
Theoretically, the code snippet should look like this.
{{#if (eq contact.gendercode 1)}} {{#if (eq contact.firstname '')}} Dear Sir {{contact.lastname}}, {{else}} Dear Sir {{contact.firstname}} {{contact.lastname}}, {{/if}} {{else if (eq contact.gendercode 2)}} {{#if (eq contact.firstname '')}} Dear Madam {{contact.lastname}}, {{else}} Dear Madam {{contact.firstname}} {{contact.lastname}}, {{/if}} {{else}} Dear Sir/Dear Madam {{/if}}
However, the last {{else}} will not work.
For a more detailed explanation you can refer to my response in this issue below.
So you can only set the title if the gender is already filled in.
Another solution is to create a custom field directly to record the title.
You can use Business Rules to set the value of this custom field based on the value of the Gender field, and then add this custom field to the Marketing Email as dynamic content.
Hey Nya ,
first of all thanks for the explanation!
The code snippet works fine, YET I need to include the same for gendercode_0 (female) and a third option if there is no gender selected to display Dear Sir/Dear Madam.
So basically I need to differentiate between gendercode_1 | gendercode_0 | and if none is selected
{{#if (eq contact.gendercode 1)}}
{{#if (eq contact.firstname '')}}
Dear Sir {{contact.lastname}},
{{else}}
Dear Sir {{contact.firstname}} {{contact.lastname}},
{{/if}}
{{/if}}
{{#if (eq contact.gendercode 0)}}
{{#if (eq contact.firstname '')}}
Dear Madam {{contact.lastname}},
{{else}}
Dear Madam {{contact.firstname}} {{contact.lastname}},
{{/if}}
{{/if}}
{{#if (eq contact.gendercode '' )}}
Dear Sir/Dear Madam
{{/if}}
Hi,
Please refer to the following documentation to add a non-empty determination for the title postfix field.
Add dynamic content to email messages (Dynamics 365 Marketing) | Microsoft Docs
You can test for empty field values by using:
{{#if (eq contact.lastname '')}}
Where ''
is two single quotation marks, not a double quotation mark. This finds empty fields, but not null fields.
Though you can't use complex Boolean expressions in your conditional expressions, you can implement similar functionality as follows:
{{#if A}}{{#if B}}<DisplayedContent>{{/if}}{{/if}}
For example, I'd like the email to show the contact's first name and last name if the gender is male and the first name exists. If it doesn't exist, show the last name only.
The code snippet should be something like:
{{#if (eq contact.gendercode 1)}} {{#if (eq contact.firstname '')}} Sehr geehrter Herr {{contact.lastname}}, {{else}} Sehr geehrter Herr {{contact.firstname}} {{contact.lastname}}, {{/if}} {{/if}}
Here are the preview results for the two male contacts. One has first name and the other doesn't have.
André Arnaud de Cal...
291,969
Super User 2025 Season 1
Martin Dráb
230,842
Most Valuable Professional
nmaenpaa
101,156