Hello Magento Friends,

Today we will discover How to Add Conditional Statement in Email Template in Magento 2. 

An email template is a predefined structure of email that includes text or images. Magento 2 admin can even add conditional statements in the email template to make it dynamic.

Let’s look at the steps to learn how to add conditional statement in Magento 2.

Steps to Add Conditional Statement in Email Template in Magento  2:

Step 1: Create blog file “Index.php” at the below path

app/code/Vendor/Extension/Block/Index

Then add the code as follows

Step 2: Create controller file “Index.php” at the below-mentioned path

app/code/Vendor/Extension/Controller/Index

Then add the following code-snippet

Step 3: Create controller file Post.php at the following path

app/code/Vendor/Extension/Controller/Index/Post.php

Then add the following code snippet

Step 4: Create an “email_index_index.xml” file for the front side form display at the below path

app/code/Vendor/Extension/view/frontend/layout

Then add the below piece of code

Step 5: Create form template “form.phtml” at the below path

app/code/Vendor/Extension/view/frontend/templates

Now add the following fragment of code

Step 6: Create an email template layout file  “email_templates.xml” at the following path

app/code/Vendor/Extension/etc

Now add the following code

Step 7: Create an email html file “customeremail.html” at the path underneath

app/code/Vendor/Extension/view/frontend/email

Then append the code given below

Step 8: Create template file “productinformation.phtml” for conditional value at the below path

app/code/Vendor/Extension/view/frontend/templates

And finally, add the below code

Conclusion:

By implementing the above steps, you can easily include conditional statements in Magento 2 email templates. Also, learn How to Customize Email Templates in Magento 2.

If you face any trouble, connect with me through the comment part and I will quickly help you find the solution.

Happy Coding!

Click to rate this post!
[Total: 2 Average: 5]