If statement in sendgrid email template

Viewed 1809

I am building email templates for Sendgrid. Is there a way to insert an if statement in the template that checks for existence of the variables coming from the server and displays or hides the row that shows that variable in the email?

1 Answers

SendGrid uses HandleBars for dynamic templates. To conditionally render something, you can use:

{{#if user.profile.male}}
  <p>Dear Sir</p>
{{else if user.profile.female}}
  <p>Dear Madame</p>
{{else}}
  <p>Dear Customer</p>
{{/if}}
Related