0

Magento CE 1.9.4.5

I created a module and successfully had it loaded. The xml is below:

<?xml version="1.0" encoding="UTF-8"?>
<layout>
    <default>
        <reference name="header">
            <block type="core/template" name="mymodule.topbar" template="topbar/content.phtml"/>
        </reference>
    </default>
</layout>

As you can see, the content is the reference name="header" in topbar/content.phtml is loaded by calling $this->getChildHtml('mymodule.topbar') in header.phtml.

I wonder if I still need to load the topbar even when header is not used, so changed the xml to:

<?xml version="1.0" encoding="UTF-8"?>
<layout>
    <default>
        <reference name="root">
            <block type="core/template" name="mymodule.topbar" template="page/html/topbar.phtml"/>
        </reference>
    </default>
</layout>

I copied the content.phml file to app/design/frontend/mymodule/mytheme/template/page/html and renamed it to topbar.phtml. It suddenly doesn't load anymore and I can't see anything wrong.

Any one please give me some advice. Thanks in advance.

0

Did you update your page layouts to now call that block?

You’ve moved the block out of the “header” template’s scope. This means your block is no longer a child of header. So the old call to getChildHtml will be empty because your block isn’t a child of “header” in the layout XML. You need to now update the root templates to call your block.

  • Thanks. You are absolutely right. I was still using getChildHtml inside the header.phtml. – ptree Sep 28 '20 at 4:41

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.