Is there any way to copy search-block in magento2?
I need to place it on completely different place on mobile resolution, but in order to so, i guess i need to copy it into another container. Any ideas?
i think you're referring to the top.search
block defined in vendor/magento/module-search/view/frontend/layout/default.xml
You can add another block in your custom layout, for example:
...
<referenceContainer name="yourContainer">
<block class="Magento\Framework\View\Element\Template"
name="top.search.mobile" as="topSearchMobile"
template="Magento_Search::form.mini.mobile.phtml" />
</referenceContainer>
...
Just remember to change the name
and as
attributes.
Then if you look at the original template file form.mini.phtml
you will notice that there are some ids to change since the quickSearch
js component relies on them.
I found a solution:
<?php echo $this->getLayout()->getBlock('top.search')->toHtml(); ?>