0

I am working on a Magento 2.1.7 shop. To achieve this, I have created a child-theme of Magento Blank.

I want to display the search bar above the top links, at the right of the logo:

enter image description here

For this purpose, I wrote the line below, in my default.xml file:

<move element="top.links" destination="header-wrapper" after="logo" />
<move element="top.search" destination="header-wrapper" before="top.links"/>

<referenceContainer name="header.panel">
  <block name="panel.top.links" class="Magento\Framework\View\Element\Html\Links" after="-">
    <arguments>
      <argument name="css_class" xsi:type="string">header links</argument>
    </arguments>
  </block>
</referenceContainer>

<referenceContainer name="header.panel">
  <block name="panel.top.search" class="Magento\Framework\View\Element\Html\Search" after="-">
    <arguments>
      <argument name="css_class" xsi:type="string">header search</argument>
    </arguments>
  </block>
</referenceContainer>

The <block name="panel.top.search" class="Magento\Framework\View\Element\Html\Search" after="-"> part produces the error: Class Magento\Framework\View\Element\Html\Search does not exist in the browser.

As you can see, on the website's homepage, the search box does not appear anywhere.

What am I doing wrong? How shall I change my code to make it work?

1 Answer 1

0

The problem is that Magento\Framework\View\Element\Html\Search doesn't exists and you can't use class attribute for block node in layout xml file with value of not exist class. Search form already added in block with top.search name.

You can see how it added in magento's module-search default.xml layout file:

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

So I think that move instruction will be enough just to move exist search block and not to create new one

3

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.