1

I'm trying to add custom block module to homepage but it does not load my block.phtml file. Here are my files: app/etc/modules/MG_Block.xml:

<config>
    <modules>
        <MG_MyBlock>
            <active>true</active>
            <codePool>local</codePool>
        </MG_MyBlock>
    </modules>
</config>

app/code/local/MG/MyBlock/etc/config.xml:

<config>
    <modules>
        <MG_MyBlock>
            <version>0.1.0</version>
        </MG_MyBlock>
    </modules>
    <global>
        <blocks>
            <mg_myblock>
                <class>MG_MyBlock_Block</class>
            </mg_myblock>
        </blocks>
    </global>
</config>`

app/code/local/MG/MyBlock/Block/Products.php:

class MG_MyBlock_Block_Products extends Mage_Core_Block_Abstract{
    public function index(){
        return "hello world";
    }
}

app/design/frontend/rwd/default/template/mg/products.phtml:

<?php echo $this->index(); ?>

app/design/frontend/rwd/default/layout/local.xml:

<layout version="0.1.0">
    <default>
        <reference name="content"> 
            <block type="mg_myblock/products" output="toHtml" name="myblock" template="mg/products.phtml" after="-" />
        </reference>
    </default>
</layout>

When I use var_dump in _construct() function in my block it shows var_dump but it does not load template file.

  • add your controller code for more idea. – Suresh Chikani Sep 29 '16 at 9:38
  • I extend Mage_Core_Block_Template instead of Mage_Core_Block_Abstract and it works. – magento_user Sep 29 '16 at 9:43
0

First add "module.xml" in layout tag in "config.xml".

<config>
    <modules>
        <MG_MyBlock>
            <version>0.1.0</version>
        </MG_MyBlock>
    </modules>
    <global>
        <blocks>
            <mg_myblock>
                <class>MG_MyBlock_Block</class>
            </mg_myblock>
        </blocks>
    </global>
    <frontend>
        <routers>
            <myblock>
                <use>standard</use>
                <args>
                    <module>myblock</module>
                    <frontName>formtest</frontName>
                </args>
            </myblock>
        </routers>
        <layout>
            <updates>
                <mymodule>
                    <file>mymodule.xml</file>
                </mymodule>
            </updates>
        </layout>
    </frontend>
</config>

Then define "module.xml".

<layout version="0.1.0">
    <formtest_myblock_index>
        <reference name="content"> 
            <block type="mg_myblock/products" output="toHtml" name="myblock" template="mg/products.phtml" after="-" />
        </reference>
    </formtest_myblock_index>
</layout>

Try with this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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