【问题标题】:Layout does not load in Custom module of MagentoMagento 的自定义模块中未加载布局
【发布时间】: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>

【问题讨论】:

标签: xml magento magento-1.7


【解决方案1】:

这是你布局的句柄标签的问题。

请看下面的例子:

<?xml version="1.0"?>
<layout version="0.1.0">
    <mymodule_adminhtml_mymodule_index>
        <reference name="content">
            <block type="mymodule/adminhtml_mymodule" name="mymodule" />
        </reference>
    </mymodule_adminhtml_mymodule_index>
</layout>

请尝试以上格式!

【讨论】:

    【解决方案2】:

    只是为了确定您是否在app/etc/modules/NAMESPACE_WSPlugin.xml 下放置了一个模块 XML 文件?

    <config>
        <modules>
                    <NAMESPACE_WSPlugin>
                            <active>true</active>
                            <codePool>community</codePool>
                    </NAMESPACE_WSPlugin>
            </modules>
    </config>
    

    同时检查你的模块是否出现在System-&gt;Configuration-&gt;Advanced-&gt;Advanced-&gt;Disable Modules Output

    最好将你的布局放在app/design/frontend/base/default下。

    【讨论】:

    • 是的,我将NAMESPACE_WSPlugin.xml 放在app/etc/modules 下,它显示在启用它的System-&gt;Configuration-&gt;Advanced-&gt;Advanced 下。我在将其放在app/design/frontend/base/default 下后也进行了检查,但即使在刷新缓存和重新索引之后也不会发生任何变化。
    【解决方案3】:

    在你的布局文件wsplugin.xml你应该使用

    &lt;block type="core/template" name="wsplugin" template="wsplugin/wsplugin.phtml" /&gt;

    【讨论】:

    • 我已经按照你的建议做了,但是即使在刷新缓存和重新索引之后也没有任何变化。
    • 这很奇怪,它对我有用,而且我确实重建了你在上面发布的模块。所以也许:文件名中有一些错字?您可能会检查您的模板路径是否正确:尝试,如果您将 wsplugin.xml 中的块分配放在 local.xml 中是否有效
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-23
    • 2010-11-09
    • 1970-01-01
    • 2012-09-18
    • 1970-01-01
    相关资源
    最近更新 更多