Magento 2 XML – How to Add Block Before Another Block

layoutmagento2magento2.2xml

I want to move minicart block to top.links block.

This did the trick for me:

<move element="minicart" destination="top.links" />

Now, I added a custom block with custom .phtml file to the top.links block too:

<referenceBlock name="top.links">
            <block class="Magento\Framework\View\Element\Template" name="fw.account" template="Magento_Theme::html/FlavourWarehouseAccountDropdown.phtml"/>
</referenceBlock>

That works as expected too.

However, I need the block "fw.account" to be rendered before the "minicart". I tried adding the "before" and "after" to blocks but with no success.

How can I add the fw.account block before minicart block? Adding before="minicart" to fw.account block didn't work…

Best Answer

Please use below code to move minicart to toplinks :

<move element="minicart" destination="top.links" after="fw.account" />