Do you want to create a new page in Magento yourself ? or Do you want to create a new module in Magento yourself ? If yes, Then ok, just spend 10 minutes and follow the steps below .
Objectives: I will create a new page in Magento whose output will be “Hello World ! I am a Magento Guy..”.
Target: Create a new module called “HelloWorld”
Step 1: Module Declaration
Create app/etc/modules/M4U_HelloWorld.xml and write below code
1 2 3 4 5 6 7 8 9 |
<?xml version="1.0"?> <config> <modules> <M4U_HelloWorld> <active>true</active> <codePool>local</codePool> </M4U_HelloWorld> </modules> </config> |
Step 2: Module Configuration
a. Create a controller class app/code/local/M4U/HelloWorld/controllers/IndexController.php
1 2 3 4 5 6 7 8 |
class M4U_HelloWorld_IndexController extends Mage_Core_Controller_Front_Action { public function indexAction() { $this->loadLayout(array('default')); $this->renderLayout(); } } |
b. Create a Block class app/code/local/M4U/HelloWorld/Block/HelloWorld.php
1 2 3 4 |
class M4U_HelloWorld_Block_HelloWorld extends Mage_Core_Block_Template { // necessary methods } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<?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> |
Define Frontend Template :
1. Define page layout in app/design/frontend/M4U/default/layout/helloworld.xml
N.B: Use default instead of M4U as template location if you use default design packages. Means create file inapp/design/frontend/default/default/layout/helloworld.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?xml version="1.0"?> <layout version="0.1.0"> <helloworld_index_index> <reference name="root"> <action method="setTemplate"><template>page/1column.phtml</template></action> </reference> <reference name="content"> <block type="helloworld/helloworld" name="hello" template="helloworld/helloworld.phtml"/> </reference> </helloworld_index_index> </layout> |
2. Create template file app/design/frontend/M4U/default/template/helloworld/helloworld.phtml and write down
N.B: Use default instead of M4U 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 urlhttp://127.0.0.1/projectname/index.php/helloworld/
and see result.
That’s it……..
Is it easy or not ? what you think ?
Coder, Please at first try yourself.
where is helloworld.phtml??
Hello
I am using magneto 1.9 and have tried zillion times.Module is not working at my end.
i have cleared cache and everything. Still not helping.
Hello World not display in front-end in magento..all folder and sub-folder are create and create file in specific folder…please help me…
Please Check your path… that code use default (base) layout directory. So move your layout to directory
Here is directory structure for the module -
\app\etc\modules\Company_Web.xml
\app\code\local\Company\Web\etc\config.xml
\app\code\local\Company\Web\controllers\IndexController.php
\app\design\frontend\base\default\layout\web.xml
\app\design\frontend\base\default\template\web\web.phtml
Fuad Abdul Jabbar
fuad_abd_jabbar@yahoo.co.id
hello Brian
If you could help me in packaging this magento module to make extension it will be appreciated. thank you
Hi Sam,
I have an undated version of this tutorial, it includes the modules files, you can find it here. http://tutorialmagento.com/step-by-step-how-to-create-hello-world-basic-module-in-magento
Hope this helps
I followed your instructions to the letter, im using magento version 1.9.1.0, and i cant get the module to display, it’s listed in advanced tab for disabling or enabling(it’s enabled) but it’s not showing.
Any advice?
Thanks.
I’m using 1.9 and made copy pasted directly from here to files just to test this but it just does not work… Examples for php files are missing but not working anyways … result is always :
Whoops, our bad…
The page you requested was not found, and we have a fine guess why.
If you typed the URL directly, please make sure the spelling is correct.
If you clicked on a link to get here, the link is outdated.
Need to take a look when more fresh
I got it working when I go to http://www.mysite.com/frontname
If I want to have this module appear in the content section of the product view page what do I need to add/change?
I tried adding another node to the layout xml file and changed to but that didn’t work. What am I missing?
Does it works on magento 1.9.0.1 version?
Yes, This Will Work in 1.9.0.1 version….
You have to refresh your cache data
Hello Brian,
It took little more than your 10min to get this working as i am new to magento and php, but this is shortest and best tutorial i have found.
Thanks you very much it cut short my learning time.
cheers,
Srinivas
Hi Srinivas, It’s great to know that my article helps you out!
Hi Brian,
Still confusing for me. I am using Magento 1.9.0.1 and I am looking a super simple tutorial to create blank template and become a home page.
E.g I have this:
Hellow World!
and I want use this fucking super simple layout to become my home page layout on Magento 1.9.0.1 to display nothing.
please help
Hi, regarding template, you may follow this series
http://tutorialmagento.com/magento-theme-development-tutorial-for-designer-part-1
Hope this helps
Thanks Brian
Will read that…
Does not work. Shows 404.
clear catch and check again…………..its work perfect
Does not work, tried this and Alan Storms tutorial on Hello World. I’m not sure why. The tutorial probably works, but I think there is some setting on my site that is stopping this! AHHHHHHHHHHHH I HATE MAGENTO SOMETIMES