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:
- Am I doing this correctly?
- Is there a difference between
action method="unsetChild"andremove name=?
Thank you
1 Answer 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"andremove 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 templatemagz/page/html/topmenu.phtmlinstead ofpage/html/topmenu.phtml... I'm unsure what is best practice here, as my theme inheritsrwd/default.maGz– maGz2016年06月01日 09:44:12 +00:00Commented Jun 1, 2016 at 9:44 -
And thank you for the clarification between the 2 block removal methods. I do understand now when to use which :)maGz– maGz2016年06月01日 09:46:04 +00:00Commented Jun 1, 2016 at 9:46