Magento 2 – Creating Custom Header Extending Magento Blank

containerslayoutmagento-2.0magento2template

I am trying to create a theme with Magento Blank as parent in Magento 2 but I can't figure it out how to change the header with a custom one.

I first remove header.container from magento blank and create my container but it is created inside page-wrapper between main-content and footer and I can't make it go before main-content.

This is my layout.xml:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="register-link" remove="true" />
        <referenceBlock name="authorization-link" remove="true" />
        <referenceBlock name="wish-list-link" remove="true" />
        <referenceBlock name="my-account-link" remove="true" />
        <referenceBlock name="top.links" remove="true" />
        <referenceBlock name="header.panel.wrapper" remove="true" />
        <referenceBlock name="header.container" remove="true" />

        <referenceContainer name="page.wrapper">
            <container name="custom.header" htmlClass="headerSection" htmlTag="div">
                <block class="Magento\Framework\View\Element\Template" name="navigation.sections" before="-" template="Magento_Theme::html/sections.phtml">

                </block>
            </container>
        </referenceContainer>

    </body>
</page>

And this is how it looks the HTML:

enter image description here

Best Answer

Well this is because your before attribute is not set.

To fix that, replace:

<container name="custom.header" htmlClass="headerSection" htmlTag="div">

With:

<container name="custom.header" htmlClass="headerSection" htmlTag="div" before="main.content">
Related Topic