0

EDIT : solved by Jonathan Hussey. See at the end of post (or below) for another question if you want to help me about overridding template and layout :)

subsidiary question : Can I override page.xml, topmenu.phtml and renderer.phtml within my module or do I have to replace them manually in the theme folders ? If so, would you mind leading me to a tutorial or explain me quickly ? I didn't seem to find easily a tutorial that match my case ...

I would like to override the topmenu.phtml, the renderer.phtml, and the template of page.xml, within my module, if possible.

Thanks for this further help :)


I a new Magento developper, so I'm trying to do simple things, and my understanding of Magento is limited...

What I want to do is to display the navigation menu (top) another way (panel-ish dropdown), by creating my own module. I looked where the current menu was defined/called and found the file design/frontend/{mytheme}/default/layout/page.xml which looks like :

<default translate="label" module="page">
    <block type="page/html" name="root" output="toHtml" template="page/3columns.phtml">
        <block type="page/html_header" name="header" as="header">
            <block type="core/text_list" name="top.menu" as="topMenu" translate="label">
                <label>Navigation Bar</label>
                <block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml">
                    <block type="page/html_topmenu_renderer" name="catalog.topnav.renderer" template="page/html/topmenu/renderer.phtml"/>
                </block>
            </block>
        </block>
    </block>
</default>

(with many oher thing around, but it's the essential)

<block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml">
    <block type="page/html_topmenu_renderer" name="catalog.topnav.renderer" template="page/html/topmenu/renderer.phtml"/>
</block>

These lines indicates we need the class Mage_Page_Block_Html_Topmenu, which is displayed in the template file design/frontend/{mytheme}/default/template/page/html/topmenu.phtml, which contains :

<nav id="nav">
    <div class="nav-megadropdown col6">
        <?php echo $this->getHtml('level-top'); // $this is the a Topmenu object ?>
    </div>
    <div style="clear:both"></div>
</nav>

The method getHtml reaches the child block catalog.topnav.renderer and gets its class (Mage_Page_Block_Html_Topmenu_Renderer and calls the render method with the template design/frontend/{mytheme}/default/template/page/html/topmenu/renderer.phtml which contains a complex but working menu (I tried it by modifiying the Mage classes and the theme phtml files, and it worked).

But now, I want to make it properly, by overridding the classes within my module (which is active and looks like Fqu_Supergroup). So i started with the config.xml :

<config>
    <modules>
        <Fqu_Supergroup>
            <version>0.1.0</version>
        </Fqu_Supergroup>
    </modules>
    <global>
        <blocks>
            <Page>
                <rewrite>
                    <html_topmenu>Fqu_Supergroup_Block_Html_Topmenu</html_topmenu>
                </rewrite>
            </Page>
        </blocks>
    </global>
</config>

And my class (Fqu_Supergroup_Block_Html_Topmenu) in my module (local/Fqu/Supergroup/Block/Html/Topmenu.php) contains only the overriden methods (_getRenderedMenuItemAttributes and _getMenuItemClasses)

So here, when I try my code, the page displays a broken menu, because it didn't use my class (I var_dump'ed the class (get_class($this)) it was used to render the menu and returned Mage_Page_Block_Html_Topmenu); And when I var_dump the included files (get_included_files()) I don't see any reference to my module at all (it is activated in the Admin panel though)...

Sorry for the long post, but thanks for your attention and any help !

subsidiary question : Can I override page.xml, topmenu.phtml and renderer.phtml within my module or do I have to replace them manually in the theme folders ?

0

While I haven't analysed your post in detail, the first thing I spot when looking through the above is you are declaring your rewrite incorrectly, Page should instead be page. This string does not match the module name i.e. the Page in Mage_Page, it instead matches the string used when declaring the resource in the module you are rewriting, so in this case in the config.xml for the Mage_Page core module:

...
<blocks>
    <page> <!-- this is the string to match -->
        <class>Mage_Page_Block</class>
    </page>
</blocks>
...

By referencing page the match against module Mage_Page is determined by inspecting the global config (which is basically one massive xml file containing all the config.xml files for all modules). The rest of the string is determined according to the class name so html_topmenu maps to class Mage_Page_Block_Html_Topmenu being the class the rewrite will apply to.

For your extra question, yes you can override any layout file or template by declaring a layout file for your module. Inside this you can declare any layout changes you want including changing templates for blocks and these changes will take priority over core layout files as your module will always load after all core modules.

  • It's the small things .... yeah, it seems to have fix the main problem ! I now have another problem because of the "extends" I think, but it's another story. I'll come around for definitive answer resolution or with other problems ! THANKS anyway :) – Florian Dec 18 '14 at 13:17

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.