I'm facing a problem developing Magento 1.9 custom module. Magento somehow doesn't recognize the action handle in my module's layout XML file. Below is simplified code that reproduces the problem for me.
Namespace: MAX
Module Name: News
app/code/local/MAX/News/etc/config.xml
<config>
<frontend>
<routers>
<max_news_news>
<use>standard</use>
<args>
<module>MAX_News</module>
<frontName>news</frontName>
</args>
</max_news_news>
</routers>
<layout>
<updates>
<news module="MAX_News">
<file>max_news.xml</file>
</news>
</updates>
</layout>
</frontend>
<global>
<blocks>
<news>
<class>MAX_News_Block</class>
</news>
</blocks>
</global>
</config>
app/code/local/MAX/News/controllers/IndexController.php
class MAX_News_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
app/design/frontend/base/default/layout/max_news.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<!-- <frontname>_<controller>_<action> -->
<news_index_index>
<reference name="content">
<block type="news/featured" name="max_news_featured" template="max_news/featured.phtml"/>
</reference>
</news_index_index>
</layout>
app/code/local/MAX/News/Block/Featured.php
class MAX_News_Block_Featured extends Mage_Core_Block_Template
{
public function getModData()
{
return array('ok', 'it', 'worked');
}
}
app/design/frontend/base/default/template/max_news/featured.phtml
<h1 style="background: black; color:#fff;">Block template</h1>
<?php var_dump($this->getModData()) ?>
Problem:
My custom block doesn't show up on http://site.dev/news
. But if I change the handle from <news_index_index>
to <max_news_news_index_index>
(<namespace>_<module>_<frontname>_<controller>_<action>
), it shows up. I cannot figure out where I went wrong. Might be something trivial.
I've inspected addActionLayoutHandles()
and it indeed adds handle as max_news_news_index_index
as a result of following line
app/code/core/Mage/Core/Controller/Varien/Action.php
$update->addHandle(strtolower($this->getFullActionName()));
I've error reporting turned on and magento is in developer mode. I'm seeing no exceptions on frontend nor in logs.
Any help would be really appreciated.
Thanks.