Question

I'm new to Magento. I'm learning to add custom Module. I have created a custom module and able to load the controller. Now i'm learning to add Blocks and Layouts. I have added the files but i'm not getting the expected output.

I have used namespace 'Nikhil' and the Module name is 'MyModule'.

When it's executed, I can see the webpage, there are no errors. But its not showing the string "MyModule Block" or its not logging the message 'i'm in Block'.

I have spend several hours debugging it. Please help

The contents of the configuration file in \test\app\etc\modules\Nikhil_MyMdoule.xml is:

<?xml version="1.0"?>
<config>
    <modules>
        <Nikhil_MyModule>        
            <active>true</active>
            <codePool>local</codePool>
        </Nikhil_MyModule>
    </modules>
</config>

Config File: app\code\local\Nikhil\MyModule\etc\config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Nikhil_MyModule>
            <version>0.0.1</version>
        </Nikhil_MyModule>
    </modules>
    <frontend>
        <routers>
            <mymodule>
                <use>standard</use>
                <args>
                    <module>Nikhil_MyModule</module>
                    <frontName>nikhil</frontName>
                </args>
            </mymodule>
        </routers>
        <layout>
            <updates>
                <mymodule>
                    <file>mymodule.xml</file>
                </mymodule>
            </updates>
         </layout>
    </frontend>
    <global>
        <blocks>
            <mymodule>
                <class>Nikhil_MyModule_Block</class>
            </mymodule>
        </blocks>
    </global>
</config>

Controller: app\code\local\Nikhil\MyModule\controllers\IndexController.php

    class Nikhil_MyModule_IndexController extends Mage_Core_Controller_Front_Action
    {
        public function indexAction()
        {
            Mage::log('im in Controller');
            $this->loadLayout(); 
            $this->renderLayout();
            Zend_Debug::dump($this->getLayout()->getUpdate()->getHandles());
        }

        public function testAction(){
            echo "custom function";
        }
    }

Block file: app\code\local\Nikhil\MyModule\Block\MyBlock.php

class Nikhil_MyModule_Block_MyBlock extends Mage_Core_Block_Template
{
    public function myfunction(){
        Mage::log('im in Block');
        return "MyModule Block";
    }
}

Sorry missed to add following files.

\app\design\frontend\base\layout\mymodule.xml

<code>
<?xml version="1.0"?>
<layout version="0.1.0">
<mymodule_index_index>
<reference name="content">
<block name="myblock" template="mymodule/mymodule.phtml" type="mymodule/myblock"/>
</reference>
</mymodule_index_index>
</layout>
</code>

And from \app\design\frontend\base\template\mymodule.phtml

echo $this->myfunction();

I'm trying to call the index Action

Was it helpful?

Solution

First, enable logging from the admin, and see if it produces any files inside "var/log" folder. If not, there might be some permission issues on the folder.

Now, back to your problem, your layout file is telling Magento to search for the template file mymodule/mymodule.phtml, so if you are going with the base theme folder, path for your template file will be app\design\frontend\base\template\mymodule\mymodule.phtml.

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