Magento 2 Layout Theme – Minicart and Searchbar Not Moving to Header Links

layoutmagento2theme

I have tried to move my search bar (top.search) and mini cart (minicart) into header.links following steps I used before which were successful. For some reason I can't work why out it's not moving!

EDIT I have made some updates below (theme inherits Luma)

templates/page/html/header.phtml

<div class="header-container">
<div class="header">
    <?php if ($this->getIsHomePage()):?>
    <h1 class="logo"><strong><?php echo $this->getLogoAlt() ?></strong><a href="<?php echo $this->getUrl('') ?>" title="<?php echo $this->getLogoAlt() ?>" class="logo"><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></a></h1>
    <?php else:?>
    <a href="<?php echo $this->getUrl('') ?>" title="<?php echo $this->getLogoAlt() ?>" class="logo"><strong><?php echo $this->getLogoAlt() ?></strong><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></a>
    <?php endif?>
    <div class="quick-access">
        <?php echo $this->getChildHtml('topSearch') ?>
        <p class="welcome-msg"><?php echo $this->getChildHtml('welcome') ?> <?php echo $this->getAdditionalHtml() ?></p>
        <?php echo $this->getChildHtml('topLinks') ?>
        <?php echo $this->getChildHtml('store_language') ?>
    </div>
    <?php echo $this->getChildHtml('topContainer'); ?>
    <?php echo $this->getChildHtml('topMenu') ?>
    <?php echo $this->getChildHtml('miniCart') ?>
</div>

magenta_theme/layout/default.xml

 <?xml version="1.0"?>
 <!--
 /**
 * Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <referenceContainer name="header.panel">
        <block class="Magento\Framework\View\Element\Html\Links" name="header.links">
        <block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"/>
        <block type="core/template" name="minicart" as="miniCart"/>
            <arguments>
                <argument name="css_class" xsi:type="string">header links</argument>
            </arguments>
        </block>
    </referenceContainer>
    <referenceBlock name="logo">
        <arguments>
            <argument name="logo_file" xsi:type="string">images/logo.jpg</argument>
            <argument name="logo_img_width" xsi:type="number">341</argument>
            <argument name="logo_img_height" xsi:type="number">60</argument>
        </arguments>
    </referenceBlock>
    <referenceContainer name="footer">
        <block class="Magento\Store\Block\Switcher" name="store_switcher" as="store_switcher" after="footer_links" template="Magento_Store::switch/stores.phtml"/>
    </referenceContainer>
    <referenceBlock name="report.bugs" remove="true"/>
    <move element="copyright" destination="before.body.end"/>
</body>
</page>

Magento_Customer/layout/default.xml

<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <referenceBlock name="header.links">
        <block class="Magento\Customer\Block\Account\Customer" name="customer" template="Magento_Customer::account/customer.phtml" before="-"/>
        <block class="Magento\Customer\Block\Account\AuthorizationLink" name="authorization-link-login" template="Magento_Customer::account/link/authorization.phtml">
            <arguments>
                <argument name="sortOrder" xsi:type="number">10</argument>
            </arguments>
        </block>
    </referenceBlock>
    <block class="Magento\Theme\Block\Html\Header" name="header" as="header">
        <arguments>
            <argument name="show_part" xsi:type="string">welcome</argument>
        </arguments>
    </block>
    <move element="header" destination="header.links" before="-"/>
    <move element="register-link" destination="header.links"/>
    <move element="top.links" destination="customer"/>
    <move element="authorization-link" destination="top.links" after="-"/>
    <move element="top.search" destination="header" />
    <move element="minicart" destination="header" as="miniCart" />

</body>

Best Answer

Try this solution, it's should help:

your_theme_root/Magento_Theme/layout/default.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="header.container" htmlClass="header-container">
            <block class="Magento\Framework\View\Element\Template" name="header.custom" template="Magento_Theme::header.phtml" />
        </referenceContainer>

        <referenceBlock name="logo">
            <arguments>
                <argument name="logo_file" xsi:type="string">images/logo.jpg</argument>
                <argument name="logo_img_width" xsi:type="number">341</argument>
                <argument name="logo_img_height" xsi:type="number">60</argument>
            </arguments>
        </referenceBlock>

        <referenceContainer name="header.panel.wrapper" remove="true" />
        <referenceContainer name="header-wrapper" remove="true" />

        <move element="logo" destination="header.custom" />
        <move element="header" destination="header.custom" />
        <move element="top.links" destination="header.custom" />
        <move element="store_language" destination="header.custom" />
    </body>
</page>

your_theme_root/Magento_Search/layout/default.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <move element="top.search" destination="header.custom" />
    </body>
</page>

your_theme_root/Magento_Checkout/layout/default.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <move element="minicart" destination="header.custom" />
    </body>
</page>

your_theme_root/Magento_Theme/templates/header.phtml

<?php
/**
 * Custom header template
 *
 * @var $block \Magento\Framework\View\Element\Template
 */
?>
<div class="header">
    <?= $block->getChildHtml('logo') ?>
    <div class="quick-access">
        <?= $block->getChildHtml('topSearch') ?>
        <?= $block->getChildHtml('header') ?>
        <?= $block->getChildHtml('top.links') ?>
        <?= $block->getChildHtml('store_language') ?>
    </div>
    <?= $block->getChildHtml('minicart') ?>
</div>

It is works for me very well:

Related Topic