2

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.

3 Answers 3

2

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>
7
  • i change it but steel it doesn't work Jun 11, 2016 at 8:07
  • @SaeedDarvish what URL are you trying to access ? Jun 11, 2016 at 8:16
  • Before change shareinosync to sync i opened mg1.dev/index.php/shareinosync/index but now i open mg1.dev/index.php/sync/index but there is not any difference , its load default layout but it doesn't put my content in it Jun 11, 2016 at 8:19
  • 1
    @SaeedDarvish what if you move your layout file from default/default to base/default ? Jun 11, 2016 at 8:31
  • 1
    @SaeedDarvish you should always put your module layout files AND template files under base/default the reason is because the fallback theme mechanism of Magento first look for those files in your_package/your_theme then under your_package/default then under base/default. So if you put those files under default/default and your package is not default those files will never be found Jun 11, 2016 at 8:44
1

Saneed, i have an issue with block class.

You have define block type prefix is in config.xml .

<blocks>
        <mymodule> <!- this call block  -->
            <class>Shareino_Sync_Block</class>
        </mymodule>
    </blocks>

So,you need to change block type prefix to sync. As because of you call a block type prefix as sync (<block type="sync/sync") at layout code

1
  • Your're right ,but steel it doesn't work Jun 11, 2016 at 7:04
1

you should always put your module layout files AND template files under base/default the reason is because the fallback theme mechanism of Magento first look for those files in your_package/your_theme then under your_package/default then under base/default. So if you put those files under default/default and your package is not default those files will never be found

1
  • That's right but did you copy this text from answers? Jul 17, 2016 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.