Skip to content

Magento 2 – move block to another using move but not working

hello I have this layout, and I would like move the block amasty.menu.toggle before items of the menu to have an hamburguer into the same horizontal list menu.

I tried this :

<move element="amasty.menu.toggle" destination="ammenu.top.menu.item" before="-">

but I always find myself outside the div at the top or bottom but never inside with the items

<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

    <body>
        <attribute name="class" value="amasty-mega-menu"/>
        <referenceContainer name="header.container"
                            htmlId="ammenu-header-container"
                            htmlClass="ammenu-header-container page-header"/>
        <referenceBlock name="head.additional">
            <referenceBlock name="header-wrapper">
                <referenceBlock name="logo" remove="true"/>
                <referenceBlock name="header.navigation.icon" remove="true"/>
<!--                toggle to move inside the horizontal menu-->
                <block class="AmastyMegaMenuLiteBlockContainer"
                       name="amasty.menu.toggle"
                       before="-"
                       template="Amasty_MegaMenuLite::components/toggle.phtml">
                    <arguments>
                        <argument name="view_model" xsi:type="object">
                            AmastyMegaMenuLiteViewModelStoreMenu
                        </argument>
                    </arguments>
                </block>

                <block class="MagentoThemeBlockHtmlHeaderLogo"
                       name="ammenu.logo"
                       after="amasty.menu.toggle"
                       template="Amasty_MegaMenuLite::components/logo.phtml">
                    <arguments>
                        <argument name="view_model" xsi:type="object">
                            AmastyMegaMenuLiteViewModelHeaderLogo
                        </argument>
                    </arguments>
                </block>
            </referenceBlock>
        </referenceBlock>

        <referenceContainer name="page.top">
            <referenceBlock name="navigation.sections">
                <action method="setTemplate">
                    <argument name="template" xsi:type="string">Amasty_MegaMenuLite::sections.phtml</argument>
                </action>
                <block class="AmastyMegaMenuLiteBlockContainer"
                       name="amasty.store.menu"
                       template="Amasty_MegaMenuLite::container.phtml">

                    <block class="MagentoFrameworkViewElementTemplate"
                           name="ammenu.robots.data"
                           template="Amasty_MegaMenuLite::components/robots_data/robots_data.phtml">
                        <block class="MagentoFrameworkViewElementTemplate"
                               name="ammenu.robots.data.item"
                               template="Amasty_MegaMenuLite::components/robots_data/item.phtml">
                        </block>
                    </block>
                    <block class="MagentoFrameworkViewElementTemplate"
                           name="ammenu.top.menu"
                           template="Amasty_MegaMenuLite::components/top_menu/wrapper.phtml">
                        <arguments>
                            <argument name="view_model" xsi:type="object">
                                AmastyMegaMenuLiteViewModelStoreMenu
                            </argument>
                        </arguments>
                        <block class="MagentoFrameworkViewElementTemplate"
                               name="ammenu.top.menu.item"
                               template="Amasty_MegaMenuLite::components/top_menu/item.phtml">
                            <arguments>
                                <argument name="view_model" xsi:type="object">
                                    AmastyMegaMenuLiteViewModelStoreMenu
                                </argument>
                            </arguments>
                            <block class="MagentoFrameworkViewElementTemplate"
                                   name="ammenu.top.menu.link"
                                   template="Amasty_MegaMenuLite::components/link.phtml">
                                <arguments>
                                    <argument name="view_model" xsi:type="object">
                                        AmastyMegaMenuLiteViewModelStoreMenu
                                    </argument>
                                </arguments>
                                <block class="MagentoFrameworkViewElementTemplate"
                                       name="ammenu.top.menu.icon"
                                       template="Amasty_MegaMenu::components/icon.phtml">
                                    <arguments>
                                        <argument name="view_model" xsi:type="object">
                                            AmastyMegaMenuLiteViewModelStoreMenu
                                        </argument>
                                    </arguments>
                                </block>
                            </block>
                        </block>
                    </block>
                </block>
                <referenceBlock name="amtheme.store.compare" remove="true"/>
                <referenceBlock name="store.links" remove="true"/>
                <referenceBlock name="store.settings" remove="true"/>
            </referenceBlock>
        </referenceContainer>
        <move element="top.search" destination="header-wrapper" after="ammenu.logo" />
        <move element="amasty.menu.toggle" destination="ammenu.top.menu.item" before="-"></move>
    </body>
</layout>