【发布时间】:2013-09-17 13:27:50
【问题描述】:
我正在为 magento 编写一个自定义模块,但在这里遇到了一些问题。我的布局 xml 不起作用。即使我没有得到任何异常或日志。在通过管理面板刷新缓存和重新索引后,我也尝试过。 hello message 打印出来,放在 IndexController.php 下,但布局不加载。
layout xml文件放在下面
/var/www/magento/app/design/frontend/default/default/layout/wsplugin.xml
config.xml
<?xml version="1.0"?>
<config>
<modules>
<NAMESPACE_WSPlugin>
<version>0.1.0</version>
<depends>
<Mage_Catalog />
</depends>
</NAMESPACE_WSPlugin>
</modules>
<frontend>
<routers>
<wsplugin>
<use>standard</use>
<args>
<module>NAMESPACE_WSPlugin</module>
<frontName>wsplugin</frontName>
</args>
</wsplugin>
</routers>
<layout>
<updates>
<wsplugin>
<file>wsplugin.xml</file>
</wsplugin>
</updates>
</layout>
</frontend>
<global>
<blocks>
<wsplugin>
<class>NAMESPACE_WSPlugin_Block</class>
</wsplugin>
</blocks>
<helpers>
<wsplugin>
<class>NAMESPACE_WSPlugin_Helper</class>
</wsplugin>
</helpers>
</global>
</config>
IndexController.php
<?php
class NAMESPACE_WSPlugin_IndexController extends Mage_Core_Controller_Front_Action {
public function indexAction() {
$this->loadLayout();
$this->renderLayout();
echo 'hello message';
}
}
?>
WSPlugin.php(在 NAMESPACE/WSPlugin/Block 下)
<?php
class NAMESPACE_WSPlugin_Block_WSPlugin extends Mage_Core_Block_Template {
public function getWSPlugin() {
return "get WS Plugin under Block";
}
}
wsplugin.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="content">
</reference>
</default>
<wsplugin_index_index>
<reference name="content">
<block type="wsplugin/wsplugin" name="wsplugin" template="wsplugin/wsplugin.phtml" />
</reference>
</wsplugin_index_index>
</layout>
wsplugin.phtml
<h4><?php echo 'Welcome in WS Plugin';
echo $this->getWSPlugin();
?></h4>
【问题讨论】:
-
这个链接已经不止一次帮助我回答了这个问题stackoverflow.com/questions/7048354/…
标签: xml magento magento-1.7