Block in reference root not loaded but loaded in reference header
-
14-04-2021 - |
Question
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.
Solution
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.