I try below code is working for add a phtml file in header of Magento.

 <reference name="header">
    <block type="your_module/yourblockclass" name="yourblockname" template="your_module/yourtemplate.phtml"/>

Add the code above to the -layou-handle in your custom layout.xml file. Fetch the block via.


from within the header.phtml file.This way it's working fine.

But Suppose you have some custom theme.

you install module and it will create the header.phtml file in app/design/frontend/default/default/page/html/header.phtml in this folder, so the custom theme header.phtml file called this file is not called.

so how to add any phtml file in header for any theme with out use of $this->getChildHtml().

1 Answer 1


You can add the block by adding output="toHtml" to its declaration. But as long as header block is not a structural one (not of the core/text_list type) you can't really control the positioning of your block inside of the header.

The problem here is that custom module which overrides generic header.phtml which is not good practice. I'd suggest refactoring the module at least moving the modifications which have to me made to header.phtml into your custom theme.


As I see in your extension there is absolutely no matter where to add the block as you will position it absolutely in any way. So you can try the following:

<reference name="header">
   <block type="your_module/your_block_class" name="your_block_name" template="your_module/your_template.phtml" output="toHtml"/>
  • yes but this easy for developer but any user can download the module and setup this will not work so. In wordpress we have function but in magento there is no other way.
    – Keyul Shah
    Commented Dec 15, 2013 at 9:45
  • The idea is that developer of any Magento module shall try not to modify default templates but to add new ones. Commented Dec 15, 2013 at 9:54
  • can you give me some tips add one phtml file in header without using $this->getChildHtml()
    – Keyul Shah
    Commented Dec 15, 2013 at 10:04
  • This is my extension link magentocommerce.com/magento-connect/catalog/product/view/id/…
    – Keyul Shah
    Commented Dec 15, 2013 at 10:20
  • As I said, it depends on where exactly in the header you want to add it. Commented Dec 15, 2013 at 12:14

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.