Hello Magento Friends,

Today we will be learning How to Display Complex Error & Success Messages in Magento 2.

It is important to notify customers about actions they perform on your website. Magento 2 provides default success and error messages for the actions taken by users in the frontend as well as the backend. It uses default functions for showing different types of action messages in the form of text.

But if you want to show a custom message for failure or successful action like adding a link along with the text. This cannot be done with default functions. For that, you need to follow the below steps.

So, let’s start

Steps to Display Complex Error & Success Messages in Magento 2:

Step 1: Go to the below path

app\code\Vendor\Extension\etc\frontend\di.xml

And add the below code

Step 2: Then move to the following path

app\code\Vendor\Extension\view\frontend\templates\messages\addCustomMessage.phtml

And add code as follows

Step 3: Add a complex success or error message in your Controller action.

Conclusion:

Thus, you can easily add your custom error and success messages in Magento 2. If you need any other customizations for your Magento 2 store, Hire a Certified Magento Developer.

Add your questions in the comments if you have any.

Happy Coding!

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