Magento Custom Extension Not Loading .phtml Template – Troubleshooting Guide

blocksmoduletheme

I've created an extension which seems to be partially working but not executing any of the code in the template file.

With the code in indexAction() just echoing, the content is output as one might expect, however with;

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

The page only returns the blank standard page template.

The frontname.xml file looks like this

<frontname_index_index>
    <reference name="content">
    <block type="core/text">
        <block type="frontname/frontname" name="frontname" template="frontname/frontname.phtml"/>
    </block>
    </reference>
</frontname_index_index>

Config.xml contains:

<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
    <Newmodule_Frontname>
        <version>0.0.1</version>
    </Newmodule_Frontname>
</modules>
<frontend>
    <routers>
        <frontname>
            <use>standard</use>
            <args>
                <module>Newmodule_Frontname</module>
                <frontname>frontname</frontname>
            </args>
        </frontname>
    </routers>
    <layout>
        <updates>
            <frontname>
                <file>frontname.xml</file>
            </frontname>
        </updates>
    </layout>
</frontend>
<global>
    <blocks>
        <frontname>
            <class>Newmodule_Frontname_Block</class>
        </frontname>
    </blocks>
</global>
</config>

Block/Frontname.php:

class NewModule_Frontname_Block_Frontname extends Mage_Core_Block_Template{
 public function myfunction(){
    return "Tesing123";
   }
 }

EDIT

I've found the exception trace as follows:

        exception 'Mage_Core_Exception' with message 'Invalid block type: Newmodule_Frontname_Block_Frontname' in /path/to/app/Mage.php:595
        Stack trace:
        #0 /path/to/includes/src/__default.php(27814): Mage::throwException('Invalid block t...')
        #1 /path/to/includes/src/__default.php(27756): Mage_Core_Model_Layout->_getBlockInstance('frontname/front...', Array)
        #2 /path/to/includes/src/__default.php(27791): Mage_Core_Model_Layout->createBlock('frontname/front...', 'frontname')
        #3 /path/to/includes/src/__default.php(27558): Mage_Core_Model_Layout->addBlock('frontname/front...', 'frontname')
        #4 /path/to/includes/src/__default.php(27524): Mage_Core_Model_Layout->_generateBlock(Object(Mage_Core_Model_Layout_Element), Object(Mage_Core_Model_Layout_Element))
        #5 /path/to/includes/src/__default.php(27529): Mage_Core_Model_Layout->generateBlocks(Object(Mage_Core_Model_Layout_Element))
        #6 /path/to/includes/src/__default.php(13911): Mage_Core_Model_Layout->generateBlocks()
        #7 /path/to/includes/src/__default.php(13836): Mage_Core_Controller_Varien_Action->generateLayoutBlocks()
        #8 /path/to/app/code/local/Newmodule/Frontname/controllers/IndexController.php(6): Mage_Core_Controller_Varien_Action->loadLayout()
        #9 /path/to/includes/src/__default.php(13985): Newmodule_Frontname_IndexController->indexAction()
        #10 /path/to/includes/src/__default.php(18380): Mage_Core_Controller_Varien_Action->dispatch('index')
        #11 /path/to/includes/src/__default.php(17910): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
        #12 /path/to/includes/src/__default.php(20535): Mage_Core_Controller_Varien_Front->dispatch()
        #13 /path/to/app/Mage.php(684): Mage_Core_Model_App->run(Array)
        #14 /path/to/index.php(102): Mage::run('', 'store')
        #15 {main}

Best Answer

Make sure following points.

  1. Make sure you have frontname part of your custom layout update handle frontname_index_index is defined inside your config.xml file. (or show us your config.xml if possible)

  2. Try this code first.

    <frontname_index_index>
        <reference name="content">
            <block type="core/template" name="frontname" template="frontname/frontname.phtml"/>
        </reference>
    </frontname_index_index>
    

    and make sure you have your template file does exist in your package/theme design directory. ie at app\design\frontend\{package}\{theme}\template\frontname\frontname.phtml

  3. If the above step worked, then you can try this.

    <frontname_index_index>
        <reference name="content">
            <block type="frontname/frontname" name="frontname" template="frontname/frontname.phtml"/>
        </reference>
    </frontname_index_index>
    
  4. If step 3 didn't work, then that indicates you have no such block types frontname/frontname. So define that then.

We can give more specific informations if you can show your config.xml file. Let me know your doubts. Good luck

EDIT

You block is not working because, you have a wrong class definition. Your class name should be NewModule_FrontName_Block_Frontname instead of NewModule_FrontName_Block_FrontName. (Also make sure, block file name should be app/code/local/NewModule/FrontName/Block/Frontname.php)

or

keep your block class name as it is and update the block layout definition like this (in this case, block file name should be app/code/local/NewModule/FrontName/Block/FrontName.php.

 <block type="frontname/frontName" name="frontname" template="frontname/frontname.phtml"/>
Related Topic