Jump to content

Magento Module Development...HellWorld


glenelkins

Recommended Posts

Hi

 

I dont know whats going on with these modules. Im writing a test one called HelloWorld. But the only output i ever seem to get is through _toHtml() function inside the block ?? In the layout config xml i have this:

 

<?xml version="1.0"?>
    <layout version="0.1.0">
        <helloworld_index_index>
            <reference name="root">
                <action method="setTemplate"><templates>page/1column.phtml</templates></action>
            </reference>
            <reference name="content">
                <block type="helloworld/helloworld" name="hello" templates="helloworld/helloworld.phtml" />
            </reference>
            
        </helloworld_index_index>
    </layout>

 

The file “helloworld/helloworld.phtml” has the content “Hello World!” but it never loads up, here is the IndexController followed by the HelloWorld block

 

<?php

class M4U_HelloWorld_IndexController extends Mage_Core_Controller_Front_Action {

    public function indexAction() {
    
        $this->loadLayout();
        $this->renderLayout();

        
    }
    
}

?>

<?php

class M4U_HelloWorld_Block_HelloWorld extends Mage_Core_Block_Template {

    function _toHtml() {
    
        return "HELLO";
        
    }
}

?>

 

All the block seems to do is load the block template file and insert what is returned from _toHtml() if i dont have this function, then nothing gets displayed!

 

Here is the module config.xml

 

<?xml version="1.0"?>
    <config>
        <global>
            <modules>
                <m4u_helloworld>
                    <version>0.1.0</version>
                </m4u_helloworld>
            </modules>
            <blocks>
                <helloworld>
                    <rewrite>
                        <helloworld>M4U_HelloWorld_Block_HelloWorld</helloworld>
                    </rewrite>
                </helloworld>
            </blocks>
        </global>
        <frontend>
            <routers>
                <helloworld>
                    <use>standard</use>
                    <args>
                        <module>M4U_HelloWorld</module>
                        <frontName>helloworld</frontName>
                    </args>
                </helloworld>
            </routers>
            <layout>
                <updates>
                    <helloworld>
                        <file>helloworld.xml</file>
                    </helloworld>
                </updates>
            </layout>
        </frontend>
    </config> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.