3

I am working on a new theme which is based on the Luma theme. I need to add a extra container to page header.my problem is that I can't identify how/where to add this.

Can anyone advise on what page i need to edit for this?

See the reference image

enter image description here

5

Add a container after="header.panel.wrapper" inside header.container. By the reference of the container add your template.

Inside your 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">
    <referenceContainer name="header.container">
        <container name="header.containertwo" as="header_containertwo" label="Page Header Container"  htmlTag="header" htmlClass="header-mini-container" after="header.panel.wrapper"/>
    </referenceContainer>
<referenceContainer name="header.containertwo">
    <block class="Magento\Framework\View\Element\Template" name="header.mini.container" template="Vendor_Module::test.phtml"/>
</referenceContainer>
</page>

In the test.phtml

<div style="border:1px solid red;" id="test123"><p>This is a test</p></div>

Out put enter image description here

Sample module

/app/code/Vendor/Module/registration.php

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Vendor_Module',
    __DIR__
);

/app/code/Vendor/Module/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="Vendor_Module" setup_version="1.0.0" schema_version="1.0.0">
    </module>
</config>

/app/code/Vendor/Module/view/frontend/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">
    <referenceContainer name="header.container">
        <container name="header.containertwo" as="header_containertwo" label="Page Header Container"  htmlTag="header" htmlClass="header-mini-container" after="header.panel.wrapper"/>
    </referenceContainer>
<referenceContainer name="header.containertwo">
    <block class="Magento\Framework\View\Element\Template" name="header.mini.container" template="Vendor_Module::test.phtml"/>
</referenceContainer>
</page>

/app/code/Vendor/Module/view/frontend/templates/test.phtml

<div style="border:1px solid red;" id="test123"><p>This is a test </p></div>
  • Do you mean the default.xml located in Magento_theme/layout? Also where do I add the test.phtml to Magento_theme/template/html ? – user159500 Sep 18 '16 at 8:47
  • OK, I've tried it and it's not showing...I've added it like this: <referenceContainer name="header.containertwo"> <block class="Magento\Framework\View\Element\Template" name="header.mini.container" template="Vendor_Module::test123.phtml"/> </referenceContainer> ... test123.html is in myTheme/Magento_theme/Templates directory...that right? – user159500 Sep 18 '16 at 12:13
  • I'm a bit confused about the "code" directory as mine is currently empty. For example my registration.php is in myVentor/myTheme/ directory. Do I still have to add these files to the code directory? – user159500 Sep 18 '16 at 16:40
  • @user159500 would you please share with us as to what did you do exactly? I'm also confused about the "code" directory as I do not have it. Magento 2.2.2 – Mohammed Joraid Feb 14 '18 at 0:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.