0

my 1column.xml file

<referenceContainer name="page.wrapper">
        <container name="header.container" as="header_container" label="Page Header Container"  htmlTag="header" htmlClass="page-header slide" before="main.content"/>
        <container name="page.top" as="page_top" label="After Page Header" after="header.container"/>
        <container name="footer-container" as="footer" before="before.body.end" label="Page Footer Container" htmlTag="footer" htmlClass="page-footer" />
    </referenceContainer>

here i want insert my custom html inside header.container

so all i did was inside my frontend/{mypachage}/{theme}/Magento_Theme/templates/html/custom-header.phtml now i want to inject header.phtml inside header tag so inside my theme/Magento_Theme/layout/default.xml i edited and added line

<referenceContainer name="header_container"> 
  <block  type="page/html" name="asd" template="html/header.phtml" />
</referenceContainer>

But nothing happens

  • Did you try with <referenceContainer name="header.container"> ? – Raphael at Digital Pianism Apr 29 '16 at 8:18
  • 1
    oh yes i tried both with name and as of original container and do i have to create class to use templates? – ujwal dhakal Apr 29 '16 at 8:20
3

you have to try with below code, in magento 2 block with type attribute are removed you have to use with class attribute.

<referenceContainer name="header_container"> 
     <block class="Magento\Framework\View\Element\Template" name="custom.header" template="Magento_Theme::html/custom-header.phtml">
</referenceContainer>

Clear cache and check again.

| improve this answer | |
  • yes this works but what does class do? – ujwal dhakal Apr 29 '16 at 8:48
  • class takes full path of your block class. you can check above class path from vendor/magento/framework/View/Element/Template.php – Rakesh Jesadiya Apr 29 '16 at 8:59
  • but my file path was inside my own dir – ujwal dhakal Apr 29 '16 at 9:13
  • you have to just give path like this , Vendor/Module/Block/Custom – Rakesh Jesadiya Apr 29 '16 at 9:15
  • your class doesnot work but class="Magento\Theme\Block\Html\Header" works – ujwal dhakal Apr 29 '16 at 9:28

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.