Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If statement in sendgrid email template

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?

like image 718
Anna Avatar asked Oct 18 '22 12:10

Anna


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}}
like image 130
Matloob Siddiqi Avatar answered Oct 21 '22 09:10

Matloob Siddiqi