1

I'm using Magento 1.8.1 with lots of changes (difficult to update) and I would like to introduce the 1.9 rwd top menu for mobiles to my website because it's really interesting. The way I want to do it is to add on my header.phtml

<?php echo $this->getChildHtml('rwdtopMenu'); ?>
<?php echo $this->getChildHtml('rwdtopSearch'); ?>
<?php echo $this->getChildHtml('rwdtopAccount'); ?>
<?php echo $this->getChildHtml('rwdtopCart'); ?>

and hide it via css with display:none when window width is lesser than a specific value.

A part from this, I've also added to my local.xml

<default>
    <reference name="root">
        <block type="core/template" name="rwdtopMenu" as="rwdtopMenu" template="rwdmenu/rwdtopmenu.phtml"/>
    </reference>
    <reference name="root">
        <block type="core/template" name="rwdtopSearch" as="rwdtopSearch" template="rwdmenu/rwdtopsearch.phtml"/>
    </reference>
    <reference name="root">
        <block type="core/template" name="rwdtopAccount" as="rwdtopAccount" template="rwdmenu/rwdtopaccount.phtml"/>
    </reference>
    <reference name="root">
        <block type="core/template" name="rwdtopCart" as="rwdtopCart" template="rwdmenu/rwdtopcart.phtml"/>
    </reference>
</default>

And in the location default/mytheme/template/rwdmenu I've created the file rwdtopmenu.phtml with some testing text on it.

<p>Some testing text</p>

But it displays nothing and I don't know why it could be. Any idea?

2

You reference block name is wrong.It should be header (<reference name="header">) instead of root ( <reference name="root"> ).

getChildHtml() loads the HTML for the child block with the name which is passed to the method.

<default>
    <reference name="header">
        <block type="core/template" name="rwdtopMenu" as="rwdtopMenu" template="rwdmenu/rwdtopmenu.phtml"/>
    </reference>
    <reference name="header">
        <block type="core/template" name="rwdtopSearch" as="rwdtopSearch" template="rwdmenu/rwdtopsearch.phtml"/>
    </reference>
    <reference name="header">
        <block type="core/template" name="rwdtopAccount" as="rwdtopAccount" template="rwdmenu/rwdtopaccount.phtml"/>
    </reference>
    <reference name="header">
        <block type="core/template" name="rwdtopCart" as="rwdtopCart" template="rwdmenu/rwdtopcart.phtml"/>
    </reference>
</default>

Get More details getChildHtml().Checkout below link:

Understanding getChildHtml in Magento

  • 2
    You should also reference the header block only once – Alex Dinca Oct 13 '15 at 10:38
  • Awesome, it worked. @Alex I had it in one root at the begining but as this didn't work I tried different ways with no succeed either. Now it's set up to one header only working perfect. Thank you both! – danibg Oct 13 '15 at 11:01

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.