0

I am trying to load a custom .phtml template using custom block. But the template isn't loading. I saw similar problems here and tried to figure out a solution, but couldn't find out where the problem is. My controller is working correctly. The url http://localhost/magento/test/index loads view correctly, but without testlayout.phtml contents.

Hers's my code

\app\code\local\Impulse\Test\controllers\IndexController.php

<?php

class Impulse_Test_IndexController extends Mage_Core_Controller_Front_Action {

    public function indexAction() {
        $this->loadLayout(false);
        $this->renderLayout();
    }

    public function testAction() {
        echo "This is test!";
    }
}

\app\code\local\Impulse\Test\etc\config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Impulse_Test>
            <version>1.0.0</version>
        </Impulse_Test>
    </modules>
    <global>
        <blocks>
            <impulse_test>
                <class>Impulse_Test_Block</class>
            </impulse_test>
        </blocks>
    <!--
        <models>
            <test>
                <class>Impulse_Test_Model</class>
                <resourceModel>test_resource</resourceModel>
            </test>
            <test_resource>
                <class>Impulse_Test_Model_Resource</class>
                <deprecatedNode>test_resource_eav_mysql4</deprecatedNode>
                <entities>
                    <test>
                        <table>impulse_test</table>
                    </test>
                </entities>
            </test_resource>
        </models>
        <resources>
            <test_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </test_write>
            <test_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </test_read>
        </resources>
    -->
    </global>
    <frontend>
        <routers>
            <impulse_test>
                <use>standard</use>
                <args>
                    <module>Impulse_Test</module>
                    <frontName>test</frontName>
                </args>
            </impulse_test>
        </routers>
        <layout>
            <updates>
                <impulse_test>
                    <file>test.xml</file>
                </impulse_test>
            </updates>
        </layout>
    </frontend>
</config>

\app\design\frontend\impulse\theme\layout\test.xml

<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
    <impulse_test_index_index>
        <reference name="content">
            <block type="impulse_test/testblock" name="testlayout_testblock" output="toHtml" template="test/testlayout.phtml"></block>
        </reference>
    </impulse_test_index_index>
</layout>

\app\code\local\Impulse\Test\Block\Testblock.php

<?php
class Impulse_Test_Block_Testblock extends Mage_Core_Block_Template {
    public function methodblock() {
        return "this is returned";
    }
}

\app\design\frontend\impulse\theme\template\test\testlayout.phtml

<?php
    echo $this->methodblock();
?>
  • Test it moving test.xml file to frontend/base/default/layout/ folder. – mageUz Jan 14 '15 at 14:44
1

I believe <impulse_test_index_index> is incorrect.

In your case it should be <test_index_index>, where Test is the modulename : from Namespace_Modulename (Impulse_Test), and index and index are the controller and actions.

If you update that in app\design\frontend\impulse\theme\layout\test.xml it should work.

  • Note if that doesn't work you can also do something like <default><remove name="root"/></default> within that layout XML file just too see if the xml file is working. (that bit of code should remove all the content on homepage if it does then you know the file is being loaded) – James Anelay - TheExtensionLab Jan 14 '15 at 21:41

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.