- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I need to display magento default error/success message into magento 2's Ves/Fasony theme layout file.
Please let me know how can i do that ?
Thanks in advance!
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try this,
we need to assign a placeholder for the message through frontend layout xml used in the module as given below inside the <body> tag:
<referenceContainer name="page.messages"> <block class="Magento\Framework\View\Element\Template" name="ajax.message.placeholder" template="Magento_Theme::html/messages.phtml"/> <block class="Magento\Framework\View\Element\Messages" name="messages" as="messages" template="Magento_Theme::messages.phtml"/> </referenceContainer>
The above layout update will make use of the magento's message template to display the messages.
Thanks!!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How can i display success or error message into home page in custom theme layout ?
Hello @yagnik_solanki
Messaging in Magento 2 is handled by a message manager object. So if you want to write messages, you need to get an instance of it. The prefered method is to inject this class into your class by adding this to your __construct method:
protected messageManager;
public function __construct(
...
\Magento\Framework\Message\ManagerInterface $messageManager,
...
){
$this->messageManager = $messageManager;
...
}
With this, you can call one of the following messages:
If found my answer useful? Please give Kudos and accept it as solution.
Ankita Biswas
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How can i display success or error message into home page in custom theme layout ?
Thanks Ankita for reply,
But i need to doing this using xml file not php code.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try this,
we need to assign a placeholder for the message through frontend layout xml used in the module as given below inside the <body> tag:
<referenceContainer name="page.messages"> <block class="Magento\Framework\View\Element\Template" name="ajax.message.placeholder" template="Magento_Theme::html/messages.phtml"/> <block class="Magento\Framework\View\Element\Messages" name="messages" as="messages" template="Magento_Theme::messages.phtml"/> </referenceContainer>
The above layout update will make use of the magento's message template to display the messages.
Thanks!!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How can i display success or error message into home page in custom theme layout ?
Thanks,
I will try
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How can i display success or error message into home page in custom theme layout ?
In Magento 2, we can achieve this in two steps:
First, we need to assign the message to 'messageManager' from your module as below:
$this->messageManager->addSuccess(__('This is a success message.'));
Secondly, we need to assign a placeholder for the message through frontend layout xml used in the module as given below inside the <HTML><HEAD></HEAD><BODY> tag:
<REFERENCECONTAINER name="page.messages">
<BLOCK class="Magento\Framework\View\Element\Template" name="ajax.message.placeholder" template="Magento_Theme::html/messages.phtml"></BLOCK>
<BLOCK class="Magento\Framework\View\Element\Messages" name="messages" as="messages" template="Magento_Theme::messages.phtml"></BLOCK>
</REFERENCECONTAINER>
The above layout update will make use of the magento's message template to display the messages.</BODY></HTML>
If found my answer useful? Please give Kudos and Accept it as Solution.
Ankita Biswas
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How can i display success or error message into home page in custom theme layout ?
Thanks for reply,
It works well
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How can i display success or error message into home page in custom theme layout ?
Hi @yagnik_solanki,
Use this extension to effortlessly display custom messages on cart, checkout & order success pages with a call to action button and custom URL. Use any of the 6 layouts to display the message.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How can i display success or error message into home page in custom theme layout ?
it works on custom module where you work all custom things .