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

时间:2015-08-10 21:49:24

标签: magento magento-1.9

我正在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: \应用\设计\前端\ RWD \默认\布局\ 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根本没有拿起这个文件。我已经尝试在samplemodule.xml中放置无效的xml,希望Magento会抛出一个错误,确认它至少被加载了,但是由于没有抛出任何错误,我认为它只是被忽略了。

我已经在SO和其他网站上阅读了无数其他类似的问题,但我已经遇到了问题,所以对这个问题的任何见解都会受到欢迎,任何导致解决方案的问题都会受到欢迎。

由于

2 个答案:

答案 0 :(得分:1)

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

\应用\代码\社区\ MP \ SampleModule \等\ 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>

\应用\设计\前端\基\默认\布局\ 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)的内容。

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

答案 1 :(得分:0)

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

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

这将设置每个页面的标题。

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