Question

I've just written a small custom menu module for a site I'm working on, and need it to replace the current base/default catalog.topnav. My module's config.xml looks like this:

<?xml version="1.0"?>
<config>
    <modules>
        <Magz_MyMenu>
            <version>0.1.0</version>
        </Magz_MyMenu>
    </modules>
    <frontend>
        <layout>
            <updates>
                <mymenu module="mymenu">
                    <file>magz_mymenu.xml</file>
                </mymenu>
            </updates>
        </layout>
    </frontend>
    <global>
        ...
        <blocks>
            <page>
                <rewrite>
                    <html_topmenu>Magz_MyMenu_Block_Html_Topmenu</html_topmenu>
                </rewrite>
            </page>
        </blocks>
        ...
    </global>
</config>

... and my layout update file magz_mymenu.xml is as follows:

<?xml version="1.0"?>
<layout>
    <default>
        <reference name="top.menu">
            <action method="unsetChild"><name>catalog.topnav</name></action>
            <block type="page/html_topmenu" name="catalog.topnav" template="magz/page/html/topmenu.phtml"/>
        </reference>
    </default>
</layout>

Now this currently works and renders as it should on the frontend, but I want to know:

  1. Am I doing this correctly?
  2. Is there a difference between action method="unsetChild" and remove name=?

Thank you

Was it helpful?

Solution

Am I doing this correctly?

What you're doing is "correct", however if what you want to do is replace the html_topmenu block with your own version, you don't need the layout, just the block rewrite in your config.xml will do.

That way the standard Magento layout will load the block with the alias page/html_topmenu and this alias will resolve to your block instead of the default block.

Is there a difference between action method="unsetChild" and remove name=?

Yes. Please see this question.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top