Skip to main content

Magento2 use equal in email template

In this wiki we will find a way to use "==" equal in the email template, actually there is no equal in the email template itself but we can refer to a phtml file and pass a variable to it then use the if/equal in the phtml file to do this you can easily add this code to the template 

in the below example we will check if the payment method is bank transfer then we will write something

{{block class='Magento\\Framework\\View\\Element\\Template' area='frontend'  payment_method=$order.getPayment().getMethod() template='Module_Vendor::banktransfer_message.phtml'}}
 

after you create the module in Magento , add this file to this path

app/code/Module/Vendor/view/frontend/templates/banktransfer_message.phtml

 

in that file you can now write this php code

<?php
$payment_method = $this->getData('payment_method');
if($payment_method == "banktransfer") {
    echo "Bla Bla Bla";
}