I use Magento 1.9 on Ubuntu 14.04.
Then, I try to create a module for magento.
But the template is not loaded/rendered, it just output Block1_construct
since I echo it from Block constructor but the layout is not red (I set the background color from template file).
Please tell me where am I wrong ?
Here is my code :
app/code/local/Ags/Module1/etc/config.xml
<config>
<modules>
<Ags_Module1>
<version>0.1.0</version>
</Ags_Module1>
</modules>
<global>
<blocks>
<blockgroup>
<class>Ags_Module1_Block</class>
</blockgroup>
</blocks>
</global>
<frontend>
<routers>
<route1>
<use>standard</use>
<args>
<module>Ags_Module1</module>
<frontName>frontname1</frontName>
</args>
</route1>
</routers>
<layout>
<updates>
<route1>
<file>ags/module1.xml</file>
</route1>
</updates>
</layout>
</frontend>
</config>
app/code/local/Ags/Module1/controllers/IndexController.php
class Ags_Module1_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
app/code/local/Ags/Module1/Block/Block1.php
class Ags_Module1_Block_Block1 extends Mage_Core_Block_Template
{
public function __construct()
{
parent::__construct();
//echo, so we know the block is called
echo 'Block1_construct';
}
public function function1()
{
//echo, so we know the block function is called
echo 'Block1_function1';
return 'Block1 function1';
}
}
app/design/frontend/base/default/layout/ags/module1.xml
<layout version="0.1.0">
<route1_index_index>
<!-- blockgroup === 'Ags_Module1_Block' -->
<block type="blockgroup/block1" name="root" output="toHtml" template="ags/page1.phtml"></block>
</route1_index_index>
</layout>
app/design/frontend/base/default/template/ags/page1.phtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hello World</title>
<style type="text/css">
body {
background-color: red;
}
</style>
</head>
<body>
<?php echo $this->function1(); ?>
</body>
</html>