I am attempting to add a slide-out menu to my Magento site, and I would like to inject the HTML by using the
<?php echo $this->getChildHtml() ?> method. This menu would be universal to the entire desktop version of my website, so I want it to appear on all of the page templates (1column, 2column-right, 2-column-left, etc). I got the menu working perfectly on all templates by copy/pasting it into all of the aforementioned page templates, but this strikes me as bad coding practice—every time I edit the menu, I don't want to have to make the same change in 4 other files. That's why I want to use the
getChildHtml() method; I would edit my
menu.phtml and all layouts would be affected uniformly.
I followed the simple tutorial here but my
getChildHtml('menu') is returning empty. I'll post my relevant code below. If someone could spot where I messed up—or failing that, suggest a different way to inject HTML dynamically (similar to JSP's
<jsp:include page="..." /> method, maybe?)—I would really appreciate it. FYI I am using Magento CE 22.214.171.124.
template/theme = warrior/default
app\design\frontend\warrior\default\layout\local.xml, I have:
<layout> <default> <reference name="root"> <block type="core/text_list" name="menu" as="menu" translate="label"> <label>Slide Menu</label> </block> </reference> <reference name="menu"> <block type="core/template" name="menu" template="menu.phtml" /> </reference> </default> </layout>
app\design\frontend\warrior\default\template\page\1column.phtml, I have (excerpt):
<div class="main-container col1-layout"> <div class="main"> <?php echo $this->getChildHtml('breadcrumbs') ?> <div class="col-main"> <?php echo $this->getChildHtml('global_messages') ?> <?php echo $this->getChildHtml('content') ?> <!-- My code --> <div> <?php echo $this->getChildHtml('menu') ?> </div> </div> </div> </div>
app\design\frontend\warrior\default\template\menu.phtml, I have:
<h1 style="background-color:yellow;"> sup dawg </h1>
And the resultant HTML in my browser is this:
<div> </div> in the correct place, after the
content block (I only have it in that specific spot to test this method. The actual menu code will go before the header).
Thanks in advance,