Magento 2 – How to Move Blocks to Other Containers

blockscontainerslayoutmagento2

Being newby I look for a workaround to move Sign in and Store switcher from header.panel to header.container. I just tried this code but won't work

<referenceContainer name="header.container">
        <referenceBlock  class="Magento\Store\Block\Switcher" name="store.settings.language" template="switch/languages.phtml"> </referenceBlock>
</referenceContainer>

Best Answer

There is a new move node in the layout XML that we have access to in M2. This node sets the declared block or container element as a child of another element in the specified order.

Example:

<move element="name.of.an.element" destination="name.of.destination.element" as="new_alias" after="name.of.element.after" before="name.of.element.before"/>

In the example you provided before you should just be able to call:

<move element="store.settings.language" destination="header.container" as="store_settings_language"/>

More information in the official M2 docs on <move> here: https://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/xml-instructions.html#fedg_layout_xml-instruc_ex_mv

Related Topic