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.
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!!
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.
Thanks Ankita for reply,
But i need to doing this using xml file not php code.
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!!
Thanks,
I will try
Thanks for reply,
It works well
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.
it works on custom module where you work all custom things .