Magento - 无法加载模块布局 xml 文件

Magento - Trouble loading module layout xml file

我正在 magento 1.9 中创建一个简单的示例模块,我希望通过我的模块在前端产品页面上显示自定义块;但是我很早就遇到了麻烦。

在我的模块 config.xml 中,我定义了一个前端布局更新,下面是完整的 config.xml 文件

<?xml version="1.0"?>
<config>
    <modules>
        <MP_SampleModule>
            <version>0.0.1</version>
        </MP_SampleModule>
    </modules>

    <frontend>
        <layout>
            <updates>
                <MP_SampleModule>
                    <file>samplemodule.xml</file>
                </MP_SampleModule>
            </updates>
        </layout>
    </frontend>
</config>

我已确认模块正在加载。

对于布局文件,我创建了 samplemodule.xml: \app\design\frontend\rwd\default\layout\samplemodule.xml

rwd 是我的活跃主题。

samplemodule.xml内容如下:

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="head">
            <action method="setTitle">
                <rel>DID THIS WORK??</rel>
            </action>
        </reference>
    </default>
</layout>

但是 Magento 似乎根本没有提取这个文件。我尝试将无效的 xml 放在 samplemodule.xml 中,希望 Magento 会抛出一个错误来确认它至少正在加载,但由于没有抛出任何错误,我相信它只是被忽略了.

我在 SO 和其他网站上阅读了无数其他类似的问题,但我遇到了瓶颈,因此欢迎任何对此问题的深入了解,并欢迎任何导致解决方案的方法。

谢谢

首先确保将其放入主题文件夹中。其次,更新引用模块名称而不是其命名空间,因此它将是

<frontend>
    <layout>
        <updates>
            <Sample_Module>
                <file>samplemodule.xml</file>
            </Sample_Module>
        </updates>
    </layout>
</frontend>

然后尝试添加:<layout version="0.1.0"> 而不是布局。然后添加:

<default>
    <reference name="head">
        <action method="setTitle"><rel>DID THIS WORK??</re></action>
    </reference>
</default>

这将设置每一页的标题。

要检查的其他事项:是否正在加载模块?

在这几天没有取得任何进展后,我决定再试一次。最后,我将文件的内容更改为以下内容,这似乎已经成功了:

\app\code\community\MP\SampleModule\etc\config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <MP_SampleModule>
            <version>0.0.1</version>
        </MP_SampleModule>
    </modules>

    <frontend>
        <layout>
            <updates>
                <MP_SampleModule module="MP_SampleModule">
                    <file>mp_samplemodule.xml</file>
                </MP_SampleModule>
            </updates>
        </layout>
    </frontend>
</config>

\app\design\frontend\base\default\layout\mp_samplemodule.xml

<?xml version="1.0" encoding="UTF-8"?>
<layout>
    <default>
        <reference name="before_body_end">
            <block type="core/template"
               name="test"
               template="mp/samplemodule/test.phtml"/>
        </reference>
    </default>
</layout>

这现在可以在页面末尾附近正确输出 test.phtml (\app\design\frontend\base\default\template\mp\samplemodule\test.phtml) 的内容。

感谢您提供的所有有助于找到解决方案的见解。