1

I am trying to move all notification message on the top below header(or any specific location)

I followed this link but this only achieve top for customer page only

Magento 2: Change message location

So that means to place message at the top (below header) i have to each and every xml file of every module?

Is there any shorthand for the same, for all pages.

2

Add this in default.xml in the below path

app/code/vendor/module/view/frontend/layout/default.xml

or

app/design/frontend/vendor/theme-name/Magento_Theme/layout/default.xml

default.xml will render in all the pages so it's an global declaration.

<?xml version="1.0"?>                                                     
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <move element="messages" destination="header.container" after='-' />
</body>                                                                  
</page>

Not tested try it and let me know.

  • Add default.xml in Magento_Theme ? – summu Mar 11 at 10:07
  • updated the answer – Prathap Gunasekaran Mar 11 at 10:09
  • 1
    Thanks worked like a charm – summu Mar 11 at 11:11
1

If you want to move block for every page you should use "Magento_Theme/layout/default.xml" in your theme-directory

0

first, create layout file in the theme layout

<layout>
<default>
    <reference name="after_body_start">
        <block type="core/template" name="top.messages" template="core/messages/top.phtml" before="-" />
    </reference>
</default>

Template: ( app/design/frontend/your_package/your_theme/template/core/messages/top.phtml )

<?php $_messageCollection = $this->getMessagesBlock()->getMessageCollection() 
?>

<?php if ($_messageCollection->count()): ?>
<div>
<?php
echo $this->getMessagesBlock()->getGroupedHtml();
$_messageCollection->clear();
?>
</div>
<?php endif; ?>

please let me know if you have any question

  • I will try your approach also – summu Mar 11 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.