Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento layout - content is not being rendered/displayed

I have gone through various Magento tutorials as well as a Magento book on layout, but I'm stuck with the following problem.

I have created a custom module, located in app/code/local/Company/Module/ . I have created a block Company_Module_Block_Ablock located in Company/Module/Block/Ablock.php. I have defined <config> ... <frontend><layout><updates><module><file>module.xml in Company/Module/etc/config.xml

config.xml also has

<global>
   <blocks>
      <module>
         <class>Company_Module_Block</class>
      </module>
   </blocks>
</global>

Inside this module.xml I have:

<layout>
    <company_module_index_index>
        <reference name="content">
            <block type="module/ablock" name="myablock" template="module/ablock.phtml" />
        </reference>
    </company_module_index_index>
</layout>

I have created a Company/Module/controllers/IndexController.php and have a indexAction defined there which does

$this->loadLayout();
$this->renderLayout();

But whatever I try I'm unable to get my ablock.phtml to display. ablock.phtml is in app/design/frontend/company/default/template/module/ablock.phtml. The theme has been enabled and is generally working on the site.

I have even tried to change module.xml inside layout so its not even using a template and even this is not displaying anything. Like this -

<reference name="content">
<block type="core/text">
    <action method="setText">
        <text>Testing</text>
    </action>
</block>
</reference>

By the way the custom theme works fine otherwise, other pages have content displayed in them in the correct place.

I have SetEnv MAGE IS DEVELOPER MODE 1 in .htaccess which is supposed to help display even warnings and things. But my systems.log and exceptions.log have no errors in them. (Yes logging is turned on)

Anyone have any advise on how to troubleshoot this or can spot a mistake in the configuration or code?

My next option seems to be hacking the core module code and logging where my module.xml is being loaded and parsed to see what is going on there.

Thanks.

like image 945
arunkumar Avatar asked Aug 13 '11 03:08

arunkumar


2 Answers

Steps to Debug Layout Update XML issues:

  1. Is your XML file (local.xml or module.xml) being loaded into the system

  2. Does the handle tag you used in your layout file match a handle being generated for your request?

The quickest way to debug step 1 is, while in developer mode with errors showing, deliberately introduce a non-well-formed error to your Layout Update XML file.

<layout <!-- notice missing closing taglayout -->
    <company_module_index_index>
        <reference name="content">
            <block type="module/ablock" name="myablock" template="module/ablock.phtml" />
        </reference>
    </company_module_index_index>
</layout>

If developer mode is on and you've cleared your cache, loading any page with the above in place will cause an error. This lets you know that Magento is trying to load your XML file. If the page loads without problem, that means you have your XML file in the wrong location, or you've misconfigured your XML in config.xml.

Next up is your checking your layout handle. You'll want to make sure you're using the right one. You can view the layout handles that were used for a particular request by calling the following after your loadLayout and renderLayout request

//from a controller action
$this->loadLayout();
$this->renderLayout();
var_dump(Mage::getSingleton('core/layout')->getUpdate()->getHandles());
exit("bailing early at ".__LINE__." in ".__FILE__);

I've found the above items usually take care of 90% of layout problems. Be sure to go through the process a few times, as it's easy to miss one step and assume something's all right when it's not. Taking my usual risk of being a shill, part of why I created Commerce Bug (commercial debugging extension) was to provide this information quickly, and at a glance, to help with debugging problems.

Based on your comments below, the problem appears to be the layout handle you're using. The handle that's generated by the system is

module_module_test

However, the handle you're defining in your layout.xml is

company_module_index_index

This is the "full action name" handle. The typical syntax for this is

frontname_controllername_actionname

Change the handle to module_module_test and you should be set.

like image 193
Alan Storm Avatar answered Nov 16 '22 13:11

Alan Storm


  • did you disable or update Magento cache?
  • is your module enabled? Is it listed in System, Configuration, Advanced, Advanced?
  • which class does your Block extend?

Regards, Alessandro

like image 39
Alessandro Ronchi Avatar answered Nov 16 '22 12:11

Alessandro Ronchi