Magento 2 – Moving Search to Navigation Section

layoutmagento2navigationsearch

Currently, I have this code in my default.xml

<referenceContainer name="page.top">
    <block class="Magento\Framework\View\Element\Template" name="top.search" as="topSearch" template="Magento_Search::form.mini.phtml"/>
</referenceContainer>

I'd like to move the search bar within the <nav> inside topmenu.html but I'm unsure of how to do that.

I tried <?php echo $this->getChildHtml('topSearch') ?> but that doesn't work.

Please help.

enter image description here

Best Answer

You have to add search block inside navigation block.

<block class="Magento\Theme\Block\Html\Topmenu" name="catalog.topnav" template="html/topmenu.phtml" ttl="3600" before="-">
    <block class="Magento\Framework\View\Element\Template" name="top.search" as="topSearch" template="Magento_Search::form.mini.phtml" />
</block>
Related Topic