Magento Module Layout

I am new to Magento and I am trying to create a layout for the module I created. I have a simple module and an IndexController that outputs "Hello World". (I use this tutorial).

Now I want to create a layout for this module, and I used this tutorial , but it does not work. Can someone point me to a tutorial or explain how layouts work in Magento?

thanks:)

Here's what I have done so far: I have a package called "Andrew" and the "Hello World" module.

Here is the config.xml file for my module:

<?xml version="1.0" encoding="UTF-8"?> <config> <modules> <Andrei_Helloworld> <version>0.1.0</version> </Andrei_Helloworld> </modules> <frontend> <routers> <helloworld> <use>standard</use> <args> <module>Andrei_Helloworld</module> <frontName>helloworld</frontName> </args> </helloworld> </routers> </frontend> </config> 

Here is the Andrei_Helloworld module:

 <?xml version="1.0" encoding="UTF-8"?> <config> <modules> <Andrei_Helloworld> <active>true</active> <codePool>local</codePool> </Andrei_Helloworld> </modules> </config> 

And here is my controller:

 class Andrei_Helloworld_IndexController extends Mage_Core_Controller_Front_Action { public function indexAction() { echo 'Hello world'; } } 

That is all I have done so far. The module is working correctly. And I want a layout for my IndexController. thanks:)

+8
layout magento
source share
1 answer

so some things are missing ...

  • declare a layout update in config.xml:

     <frontend> ... <layout> <updates> <helloworld> <file>helloworld.xml</file> </helloworld> </updates> </layout> ... </frontend> 
  • create the XML layout file in the application / design / interface / base / default / layout / helloworld.xml , and in it you will create a link to your module / controller / action:

     <?xml version="1.0"?> <layout> <helloworld_index_index> <reference name="content"> <block type="core/template" name="helloworld" template="helloworld.phtml" /> </reference> </helloworld_index_index> </layout> 
  • create the phtml file that you just installed as a template in your xml layout file, i.e. app / design / frontend / base / default / template / helloworld.phtml :

     this is the content of helloworld.phtml 
  • to load and display all this in the action of your controller, replace the echo statement with:

     public function indexAction() { $this->loadLayout(); $this->renderLayout(); } 
  • disable cache, refresh browser, lean back and enjoy
+21
source share

All Articles