1

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

1

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.

  • Great, thank you Robbie. The thing is that I have all of my custom templates contained within a similar folder structure inside of app/design/frontend/magz/default/template/magz/.... So I would have to have the block reference the correct template magz/page/html/topmenu.phtml instead of page/html/topmenu.phtml ... I'm unsure what is best practice here, as my theme inherits rwd/default. – maGz Jun 1 '16 at 9:44
  • And thank you for the clarification between the 2 block removal methods. I do understand now when to use which :) – maGz Jun 1 '16 at 9:46

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.