How to add IF statement to email templates

I have templates for email invoices/reminders that contain things like this:

Invoice #$number for <b>$amount</b> due by <b>$due_date</b>

When an invoice is sent that has no due date, it is still showing the ‘due by’. How to make portion of the email template conditional? i.e. if ($due_date){ due by $due_date } would be in php.
I know I can create separate manual templates and select them for invoices without due date, but that’s not the point… In other invoice system I am used to the due date section being hidden from the email if there is no due date.

Also I would like the IF statement to conditionally display something in the template. For example I don’t want an online payment info to show if the online payment option is disabled for the invoice.

To view your invoice, click the link below.

<b><h3><a href="$view_url">Review and Pay</a></h3></b>
Visa, Mastercard, Amex, E-Transfer


The app doesn’t currently support if statements in email templates, feel free to create an issue here to request the feature: