Reading list Switch to dark mode

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

    Updated 12 July 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.

    Start your headless eCommerce
    Find out More

    We would be happy to help. Happy Coding!!

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*

    Be the first to comment.

    Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home