Create Custom Layout Module in Magento 1.9

controllersfrontendlayoutmagento-1.9module

Hi i just created custom module in magento and its frontend doesn't work.

The config file :

<?xml version="1.0"?>
<config>
<modules>
    <Shareino_Sync>
        <version>0.1.0</version>
    </Shareino_Sync>
</modules>

<global>
     <helpers>
        <sync>
            <class>Shareino_Sync_Helper</class>
        </sync>
    </helpers>
    <blocks>
        <sync>
            <class>Shareino_Sync_Block</class>
        </sync>
    </blocks>
</global>
<frontend>
    <routers>
        <sync>
            <use>standard</use>
            <args>
                <module>Shareino_Sync</module>
                <frontName>sync</frontName>
            </args>
        </sync>
    </routers>
    <layout>
        <updates>
            <sync>
                <file>shareino_front.xml</file>
            </sync>
        </updates>
    </layout>
</frontend>

</config>

The layout file :

# File in : app/design/frontend/default/default/layout/shareino_front.xml
<layout version="0.1.0">
    <sync_index_index>
        <reference name="content">
            <block type="sync/sync" name="sync" template="sync_index.phtml" />
        </reference>
    </sync_index_index>
</layout>

And sync_index.phtml :

# file in app/design/frontend/default/default/template/sync_index.phtml
<h1>
    Test Text
</h1>

I created a block that named Sync.php

class Shareino_Sync_Block_Sync extends Mage_Core_Block_Template
{
    public function myfunction()
    {
        return "Hello tuts+ world";
    }
}

At the end my controller :

class Shareino_Sync_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction(){

            $this->loadLayout();


            $this->renderLayout();

    }
    public function testAction(){
        echo "index Action";
    }
}

I think i done every think well , but when i load the action url in browser it doesn't my layout. please help me to know my wrong.

Best Answer

The problem is that your front route does not match your layout and controllers.

You need to replace the following:

 <frontName>shareinosync</frontName>

With:

 <frontName>sync</frontName>