Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

Liquid Content Snippet White Space Control

(0) ShareShare
ReportReport
Posted on by 2

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:

pastedimage1634113714975v1.png

Thanks!

 

  • Newmayer2384 Profile Picture
    Newmayer2384 2 on at
    RE: Liquid Content Snippet White Space Control

    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!

  • Nya Profile Picture
    Nya 29,058 on at
    RE: Liquid Content Snippet White Space Control

    Hi,

    If the issue has been solved, it would be appreciated if you could click "Yes" to verify my answer.

    Image

    If there is any further doubt, please do not hesitate to let me know.

  • Suggested answer
    Nya Profile Picture
    Nya 29,058 on at
    RE: Liquid Content Snippet White Space Control

    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.

    ( ) Salutation: If-Else-Statement is not working properly - Dynamics 365 Marketing Forum Community Forum

    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.

  • Newmayer2384 Profile Picture
    Newmayer2384 2 on at
    RE: Liquid Content Snippet White Space Control

    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}}

  • Suggested answer
    Nya Profile Picture
    Nya 29,058 on at
    RE: Liquid Content Snippet White Space Control

    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.

    pastedimage1634116225907v2.pngpastedimage1634116246367v3.png

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,969 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,842 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans