Select Page

How to use conditional (if) statement in email templates Magento2

Radhika Garg
Published: July 12, 2022

In this guide, we will learn how we can use if condition in email templates in magento2.
There are two ways to achieve to the result:
1. We can use depend tag which check whether that variable has some value or not. You will need to add following code in your email template:

{{depend info.getNotAllowDiscount()}}
            <h2 style="border-bottom:none;">{{trans 'Review Products'}}</h2>

2. We can use block technique. For example, insert this block in your template:

{{block class=’Magento\Framework\View\Element\Template’ area=’frontend’ template=’Vendor_Module::email/info.phtml’ order=$order}}
In your custom template, we can check whatever you want.
Example here: vendor/magento/module-sales/view/frontend/email/shipment_new.html

We hope it will help you. Thank you!!

If any issue or doubt please feel free to mention in comment section.

We would be happy to help. Happy Coding!!