Question

I am trying to nest one block inside another block but the child block isn't showing when I set custom block type.

If I set both blocks as page/html then both blocks show fine:

<?xml version="1.0"?>
<layout version="0.1.0">
    <mobilemenu_index_index>
        <block type="page/html" name="root" output="toHtml" template="company_mobilemenu/test_page.phtml">
            <block type="page/html" name="company_mobilemmenu" template="company_mobilemenu/menu.phtml" />
        </block>
    </mobilemenu_index_index>
</layout>

But when I declare my custom block type so that I can use the custom block methods the block doesn't show.

<?xml version="1.0"?>
<layout version="0.1.0">
    <mobilemenu_index_index>
        <block type="page/html" name="root" output="toHtml" template="company_mobilemenu/test_page.phtml">
            <block type="mobilemenu/mobilemenublock" name="company_mobilemmenu" template="company_mobilemenu/menu.phtml" />
        </block>
    </mobilemenu_index_index>
</layout>

I have made this file: app/code/local/Company/MobileMenu/Block/MobileMenuBlock.php that has this contents:

<?php
class Company_MobileMenu_Block_MobileMenuBlock extends Mage_Core_Block_Template
{
    public function getNestedMenu()
    {
        return 'nested menu goes here';
    }
}

In my config.xml I register it like so:

<config>
    <modules>
        <Company_MobileMenu>
            <version>0.1.0</version>
        </Company_MobileMenu>
    </modules>
    <global>
        <blocks>
            <mobilemenu>
                <class>Company_MobileMenu_Block</class>
            </mobilemenu>
        </blocks>
    </global>
    <frontend>
        <routers>
            <mobilemenu>
                <use>standard</use>
                <args>
                    <module>Company_MobileMenu</module>
                    <frontName>mobilemenu</frontName>
                </args>
            </mobilemenu>
        </routers>
        <layout>
            <updates>
                <mobilemenu>
                    <file>company_mobilemenu.xml</file>
                </mobilemenu>
            </updates>
        </layout>
    </frontend>
</config>

What am I doing wrong with custom block registration?

Was it helpful?

Solution

change type="mobilemenu/mobilemenublock" to type="mobilemenu/mobileMenuBlock"

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