Magento -麻烦加载模块布局xml文件



我在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>

我已经确认模块正在加载。

对于布局文件,我创建了samplmodule .xml: app 设计前端 rwd布局默认 samplemodule.xml

rwd是我的活动主题。

samplmodule .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似乎根本没有捡起这个文件。我曾尝试在samplemodule.xml中放置无效的xml,希望Magento会抛出一个错误,确认它至少正在加载,但由于没有抛出错误,我被引导相信它只是被忽略了。

我在SO和其他网站上读过无数类似的问题,但我遇到了瓶颈,所以任何对问题的见解都会受到欢迎,任何导致解决方案的事情都会受到赞扬。

谢谢

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

app 代码社区议员 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 设计前端基地默认布局 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 (appdesignfrontendbasedefaulttemplatempsamplemoduletest.phtml)在页面末尾。

感谢您提供的见解,这对找到解决方案很有帮助。

首先确保你把它放在你的主题文件夹中。其次,更新引用了模块名,而不是它的命名空间,所以它应该是

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

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

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

这将设置每一页的标题。

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