Can I add the search box to a template without xml?
I need to create a dropdown with the search box when I click on a magnifying glass icon.
Can I add the search box to a template without xml?
I need to create a dropdown with the search box when I click on a magnifying glass icon.
You can call search box
by following code in phtml:
<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magento_Search::form.mini.phtml")->toHtml();?>
Hope above will help!
Update I
If you want this search bar with default one you need to create copy of form.mini.phtml
say form.mini.custom.phtml
from:
Mage2Root/vendor/magento/module-search/view/frontend/templates/form.mini.phtml
to
Mage2Root/app/design/frontend/{Package}/{theme}/Magento_Search/templates/form.mini.custom.phtml
change ids from search_mini_form
to search_mini_form_custom
and input id from search
to search.custom
finally call this by:
<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magento_Search::form.mini.custom.phtml")->toHtml();?>