I have a custom module with the following:
magento-project/app/code/local/Hunique/Customs/etc/config.xml
<?xml version="1.0" ?>
<config>
<modules>
<Hunique_Customs>
<version>1.0.1</version>
</Hunique_Customs>
</modules>
<global>
<models>
<custommodule>
<class>Hunique_Customs_Model</class>
<resourceModel>custommodule_resource</resourceModel>
</custommodule>
<custommodule_resource>
<class>Hunique_Customs_Model_Resource</class>
<entities>
<custommodule>
<table>custommodule</table>
</custommodule>
<questions>
<table>questions</table>
</questions>
<answers>
<table>answers</table>
</answers>
</entities>
</custommodule_resource>
</models>
<resources>
<custommodule_setup>
<setup>
<module>Hunique_Customs</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</custommodule_setup>
<custommodule_read>
<connection>
<use>core_read</use>
</connection>
</custommodule_read>
<custommodule_write>
<connection>
<use>core_write</use>
</connection>
</custommodule_write>
</resources>
<blocks>
<custommodule>
<class>Hunique_Customs_Block</class>
</custommodule>
</blocks>
<helpers>
<hunique_customs>
<class>Hunique_Customs_Helper</class>
</hunique_customs>
</helpers>
</global>
<frontend>
<routers>
<custommodule>
<use>standard</use>
<args>
<module>Hunique_Customs</module>
<frontName>custommodule</frontName>
</args>
</custommodule>
</routers>
<layout>
<updates>
<custommodule>
<file>custommodule.xml</file>
</custommodule>
</updates>
</layout>
</frontend>
<admin>
<routers>
<adminhtml>
<use>admin</use>
<args>
<modules>
<Hunique_Customs before="Mage_Adminhtml">Hunique_Customs</Hunique_Customs>
</modules>
</args>
</adminhtml>
</routers>
</admin>
<adminhtml>
<layout>
<updates>
<custommodule>
<file>custommodule.xml</file>
</custommodule>
</updates>
</layout>
</adminhtml>
Then I have the /magento-project/app/code/local/Hunique/Customs/etc/adminhtml.xml in the same folder
<config>
<menu>
<hunique>
<title>Hunique</title>
<sort_order>1</sort_order>
<children>
<customs_qa module="hunique_customs">
<title>Questions And Answers</title>
<sort_order>1</sort_order>
<action>adminhtml/custommodule</action>
</customs_qa>
</children>
</hunique>
</menu>
Then in the desing i have:
/magento-project/app/design/adminhtml/default/default/layout/custommodule.xml
<?xml version="1.0"?>
<layout>
<adminhtml_custommodule_index>
<reference name="content">
<block type="core/template" output="toHtml" name="templateBlock" template="custommodule/questions-and-answers.phtml" />
</reference>
</adminhtml_custommodule_index>
</layout>
and I have the file /magento-
project/app/design/adminhtml/default/default/templates/custommodule/questions-and-answers.phtml but that just contains an h1 tag with TEST in it now.
I also have the controller:
/magento-project/app/code/local/Hunique/Customs/controllers/CustommoduleController.php
<?php
class Hunique_Customs_CustommoduleController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
var_dump(Mage::getSingleton('core/layout')->getUpdate()->getHandles());
$this->loadLayout();
$this->renderLayout();
}
}
I have the var dump to see if i had any handles but that is an empty array.
My page loads from the admin menu..
My routes and admin menu work fine, i just can't get my phtml to show up… anyone that can point me in the right direction?
Best Answer
The code you provided should work as it is. Although both your
config.xml
andadminhtml.xml
files don't have their<config>
tags closed, I suspect you just made this mistake when pasting code here, because otherwise you'd see an error instead of a page with empty content area.My advice is that you should search for typos in file names or wrong directories nesting. Also, your
var_dump
is empty, because you try to show layout handles before actually loading the layout. You have to switch the first two lines in your action:Also, you can also make sure that your admin panel uses the
default/default
package/theme or that it's in the fallback chain. If it's using some other package (e.g.custompackage/default
), it won't look indefault/default
. If you're not sure, you can always place your layout update xml and your template inbase/default
instead. It doesn't exist in the admin panel, but you can create it and it will be used as the last fallback.Let me know if it helps.