How To

How to Add Multiple Admin Notification Messages in Magento 2

Serving a one-stop business solution, Magento is never failed to keep its CMS updated on a regular basis with some fixes and features. And every time, when there is a new update you will able to see one tiny admin notification at the top. Which is very helpful in terms of notifying the user without any popup or distraction. So, if you are a Magento developer and developing your very own extension that serves regular updates to your users then this will be a most wanted feature for you. You can also use such notification to remind your customer for pending updates or offers as part of marketing. However, using the below code you will only be able to send notice type notification to the admin users. Also, there is no button to close it, even if the admin refresh the page notification will display again.
To do the same first, we need to create “default.xml” file inside your layout folder and paste below code in that file.
app\code\Vendor\Extension\view\adminhtml\layout

<pre class="lang:default decode:true">
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceContainer name="global.notices">
        <block class="Magento\Backend\Block\Page\Notices" name="custom_notices" as="custom_notices" after="global_notices" template="Vendor_Extension::page/notices.phtml"/>
    </referenceContainer>
</page>
</pre>

Now you have to create one more file “notices.phtml” at this path.
app\code\Vendor\Extension\view\adminhtml\templates\page\

<pre class="lang:default decode:true">
<div class="messages">
    <div class="message message-warning message-demo-mode">
        <?php echo __("Notification Message 1"); ?>
    </div>
</div>
<div class="messages">
    <div class="message message-warning message-demo-mode">
        <?php echo __("Notification Message 2"); ?>
    </div>
</div>
</pre>

Simply clear the cache and that’s it.

Lastly, if you found this blog helpful, don’t forget to share it with your colleagues and Magento Friends and Let us know if you are facing any issue while implementing this code.
Happy Coding!

Click to rate this post!
[Total: 10 Average: 5]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

Recent Posts

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

1 day ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

1 day ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

2 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

3 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

5 days ago

How Upcoming Cookie Changes Will Affect Your E-commerce Website?

The e-commerce world is constantly in flux. New tech and strategies emerge daily to help…

5 days ago