1

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?

2 Answers 2

0

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.

0

I found a solution:

<?php echo $this->getLayout()->getBlock('top.search')->toHtml(); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.