0

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>

2
  • check your path again it should be in Magento_Customer Oct 28, 2017 at 5:58
  • ^ Typo by me, it is indeed in Magento_Customer not MagentoCustomer Oct 28, 2017 at 14:53

2 Answers 2

0

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:

10
  • I am using Magento 2. I should probably mention I am completely new to Magento. What would be the alternative for local.xml? The directory is indeed Magento_Customer (I had mistyped). Oct 28, 2017 at 15:02
  • I have tried your above solution, the search bar and mini cart are now gone off the page (completely). I suppose this is a start? But even when I refresh the page, the search bar and cart will not appear in plain text briefly (client side compilation) Oct 28, 2017 at 15:16
  • I think alternative is your_theme_root/Magento_Theme/layout/default.xml. It's main layout of the theme. Oct 28, 2017 at 15:17
  • Your theme inherits from other theme? blank or Luma Oct 28, 2017 at 15:21
  • Block header with logo now is showing? Oct 28, 2017 at 15:30
0

@Evgeny,

Thanks for above solution, but still i am getting the error inconsole and mincart content not showing can you please tell me what was reasion behind this error and how to resolve.

Kindly take a look on attached screen-shot.enter image description here

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.