1

I want to set my custom phtml to header in magento 2? i want to display my phtml in all pages so i want to add my phtml in header.

i am trying to search in core files but i can't get it.

In layout how to set template to add phtml in header.I want to add my phtml without changes of admin blocks.

Is that possible to do this? How can i do this?

1 Answer 1

5

You can use default.xml to add your phtml in header

<?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>
    <referenceBlock name="header.container">
        <block class="Magento\Framework\View\Element\Template" name="example" after="-" template="Company_Example::example.phtml"/>
    </referenceBlock>
</body> 
</page>

In referenceBlock name you can use header.container or header.panel

1
  • What is file location of default.xml ??
    – Manish
    Mar 26, 2020 at 13:50

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.