Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    7

    Post Create new module “HelloWorld” – in Magento

    Create new module “HelloWorld” – in Magento how .?

  2. #2
    Registered User
    Join Date
    Apr 2011
    Posts
    8
    Do you want to create a new page in Magento ? or Do you want to create a new module in Magento ? If yes, Then ok, just spend 10 minutes and follow below steps.

    Target: Create a new module called “HelloWorld”
    Step 1: Module Declaration
    Create app/etc/modules/Tatva_HelloWorld.xml and write below code

    1
    <?xml version="1.0"?>

    2
    <config>

    3
    *********************************************<modu les>

    4
    ************************************************** ******************************<Tatva_HelloWorld>

    5
    ************************************************** ************************************************** ********************<active>true</active>

    6
    ************************************************** ************************************************** ********************<codePool>local</codePool>
    7
    ************************************************** ******************************</Tatva_HelloWorld>

    8
    *********************************************</modules>

    9
    </config>


    Step 2: Module Configuration

    a. Create a controller class app/code/local/Tatva/HelloWorld/controllers/IndexController.php

    1
    class Tatva_HelloWorld_IndexController extends Mage_Core_Controller_Front_Action
    2
    {

    3
    ********************public function indexAction()

    4
    ********************{

    5
    *************************$this->loadLayout(array('default'));

    6
    *************************$this->renderLayout();

    7
    ********************}

    8
    }


    b. Create a Block class app/code/local/Tatva/HelloWorld/Block/HelloWorld.php

    1
    class Tatva_HelloWorld_Block_HelloWorld extends Mage_Core_Block_Template
    2
    {

    3
    **********// necessary methods

    4
    }


    c. create configuration xml in app/code/local/Tatva/HelloWorld/etc/config.xml

    01
    <?xml version="1.0"?>

    02
    <config>

    03
    ********************<global>

    04
    ****************************************<modules>

    05
    ************************************************** ******************************<tatva_helloworld>

    06
    ************************************************** ************************************************** ********************<version>0.1.0</version>

    07
    ************************************************** ******************************</tatva_helloworld>

    08
    ****************************************</modules>

    09
    ********************<blocks>

    10
    ************************************************** **********<helloworld>

    11
    ************************************************** ******************************<rewrite>

    12
    *********************************************<hell oworld>Tatva_HelloWorld_Block_HelloWorld</helloworld>
    13
    ****************************************</rewrite>

    14
    ************************************************** **********</helloworld>

    15
    *************************</blocks>

    16
    *****

    17
    ****************************************</global>

    18
    ***********************************<frontend>

    19
    ************************************************** ******************************<routers>

    20
    ************************************************** ************************************************** ********************<helloworld>

    21
    ************************************************** ************************************************** ************************************************** **********<use>standard</use>

    22
    ************************************************** ************************************************** ************************************************** **********<args>

    23
    ************************************************** ************************************************** ************************************************** ****************************************<module>Ta tva_HelloWorld</module>
    24
    ************************************************** ************************************************** ************************************************** ****************************************<frontName >helloworld</frontName>
    25
    ************************************************** ************************************************** ************************************************** **********</args>

    26
    ************************************************** ************************************************** ********************</helloworld>

    27
    ************************************************** ******************************</routers>

    28
    ****************************************<layout>

    29
    ************************************************** **********<updates>

    30
    ************************************************** ******************************<helloworld>

    31
    ************************************************** ************************************************** **********<file>helloworld.xml</file>

    32
    ************************************************** ******************************</helloworld>

    33
    ************************************************** **********</updates>

    34
    ************************************************** **********</layout>

    35
    ****************************************</frontend>

    36
    </config>


    Define Frontend Template :

    1. Define page layout in app/design/frontend/Tatva/default/layout/helloworld.xml
    N.B: Use default instead of Tatva as template location if you use default design packages. Means create file in app/design/frontend/default/default/layout/helloworld.xml

    01
    <?xml version="1.0"?>

    02
    *****

    03
    ********************<layout version="0.1.0">

    04
    *****

    05
    ****************************************<helloworl d_index_index>

    06
    ************************************************** **********<reference name="root">

    07
    ************************************************** ******************************<action method="setTemplate"><template>page/1column.phtml</template></action>
    08
    ************************************************** **********</reference>

    09
    ************************************************** **********<reference name="content">

    10
    ************************************************** ******************************<block type="helloworld/helloworld" name="hello" template="helloworld/helloworld.phtml"/>
    11
    ************************************************** **********</reference>

    12
    ****************************************</helloworld_index_index>

    13
    *****

    14
    ********************</layout>


    2. Create template file app/design/frontend/Tatva/default/template/helloworld/helloworld.phtml and write down
    N.B: Use default instead of Tatva as template location if you use default design packages. Means create file in app/design/frontend/default/default/template/helloworld/helloworld.phtml
    Hello World ! I am a Magento Guy..
    Hey, new module is ready to run and hit browser with url

    http://127.0.0.1/projectname/index.php/helloworld/
    Last edited by mtthwsmith8; 10-29-2013 at 08:33 AM.

  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    5
    After reading through everything I can find I’ve nearly been able to create a simple custom module as per the tutorials/threads etc, the one thing that isn’t working is the layout xml for the module, it seems to be completely ignored - I think I’m missing something so basic no one every posts it, every thread related to this topic seems to end with “oh I’ve got it working now” and no final explanation wink
    Hopefully someone can help clear this up for me!
    To strip it back to complete basics I’m trying to create a Hello World block in a custom module which is displayed in whatever the current theme is.

    Here’s what I’ve done that nearly works:

    Created a new class in /app/code/local/Mycompany/Hello/Block/View.php

    <?php
    class Mycompany_Hello_Block_View extends Mage_Core_Block_Template {
    private $message;

    protected function createMessage($msg) {
    $this->message = $msg;
    }

    public function receiveMessage() {
    if($this->message != '') {
    return $this->message;
    } else {
    $this->createMessage('Hello World');
    return $this->message;
    }
    }
    }


    <?xml version="1.0"?>
    <config>
    <modules>
    <Mycompany_Hello>
    <version>0.1.0</version>
    </Mycompany_Hello>
    </modules>
    <global>
    <blocks>
    <hello>
    <class>Mycompany_Hello_Block</class>
    </hello>
    </blocks>
    </global>
    </config>


    <config>
    <modules>
    <Mycompany_Hello>
    <active>true</active>
    <codePool>local</codePool>
    <version>0.1.0</version>
    </Mycompany_Hello>
    </modules>
    </config>

    There is a phtml template for this as well, in /frontend/default/default/Mycompany/hello.phtml

    <div class="block-content">
    <h1>HERE I AM</h1>
    <?php
    Zend_Debug::dump($this);
    echo $this->receiveMessage();?>
    </div>

    Now I want to show the results on the product info page in the current theme. So if I edit /frontend/default/default/layout/catalog.xml I can call this module and template and it works fine

    <block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
    ...
    <block type="hello/view" name="Mycompany.hello.block" as="hello_block" template="Mycompany/hello.phtml" />
    ...
    </block>

    And to show it I call the block inside the product/view.phtml file

    <?php echo $this->getChildHtml('hello_block');?>

    This works but here’s where I get lost - what I don’t understand is why I can’t seem to create a new layout xml file for this module, I can’t seem to get the syntax right.

    From all the other threads this seems to be the ‘right thing to do’ and I thought I should be able to avoid modifying the default/layout/catalog.xml and instead create a default/layout/hello.xml file like this:
    <layout version="0.1.0">
    <hello_index_index>
    <reference name="product.info">
    <block type="hello/view" name="Mycompany.hello.block" as="hello_block" template="Mycompany/hello.phtml" />
    </reference>
    </hello_index_index>
    </layout>

    I’ve tried <hello>, <hello_index>, <hello_index_index> and even breaking the xml <he llo> to force an error, but the file doesn’t appear to be read at all. Have I just got the filename wrong or am I barking up the wrong tree?

    I’m sure this is a really, really, simple mistake but I’m stumped!

    Based on your layout handle <hello_index_index> You are missing the controller:

    \app\code\local\Mycompany\Hello\controllers\IndexC ontroller.php:

    class Mycompany_Hello_IndexController extends Mage_Core_Controller_Front_Action
    {
    public function indexAction()
    {
    $this->loadLayout();
    $this->renderLayout();
    }
    }
    The URL is

    Mage::getBaseUrl('hello/index'); //yourdomain.com/hello/index/

  4. #4
    Senior Member
    Join Date
    Apr 2014
    Posts
    264
    thanx for sharing nice information with us i strongly believe it is helpful for me and my other forum friends who want to more information about this topic.

  5. #5
    Registered User
    Join Date
    Aug 2017
    Posts
    65

    Use Magento Layout XML File to Customization in Module

    Customizing module with Magento layout XML file is very easy, you can add custom titles, meta tags, keywords or a description of your Magento module page. You can easily add this custom information to all existing, core or newly created modules.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

  Find Web Hosting      
  Shared Web Hosting UNIX & Linux Web Hosting Windows Web Hosting Adult Web Hosting
  ASP ASP.NET Web Hosting Reseller Web Hosting VPS Web Hosting Managed Web Hosting
  Cloud Web Hosting Dedicated Server E-commerce Web Hosting Cheap Web Hosting


Premium Partners:


Visit forums.thewebhostbiz.com: to discuss the web hosting business, buy and sell websites and domain names, and discuss current web hosting tools and software.