【问题标题】:Setting template header to text/xml in Magento在 Magento 中将模板标题设置为 text/xml
【发布时间】:2013-12-25 23:21:37
【问题描述】:

我有 stats.phtml,它是一个动态 XML 文件。

我在文件开头添加了<?php header("Content-type: text/xml"); ?>,但由于某种原因页面仍然有text/html 标头。

该页面的布局定义:

    <reference name="content">
        <block type="stats/stats" name="stats" template="stats/stats.phtml" />
    </reference>

我可以为 XML 模板设置正确的标头吗?

【问题讨论】:

  • header('Content-Type: application/xml; charset=utf-8'); 和内容&lt;?xml version="1.0"?&gt;?
  • 同样的结果,没有标题改变

标签: php xml magento


【解决方案1】:

那是因为你的标题内容类型已经被page/html/head.phtml设置了

您必须添加您的客户负责人,以这种方式定义您的自定义标题内容类型

复制page/html/head.phtml并重命名为page/html/head2.phtml

修改head2.phtml中的内容类型

<meta http-equiv="Content-Type" content="text/xml" />

然后将此代码添加到您的布局 xml 中

<reference name="head">
        <action method="setTemplate"><template>page/html/head2.phtml</template></action>
</reference>
<reference name="content">
    <block type="stats/stats" name="stats" template="stats/stats.phtml" />
</reference>

因此它将用您的自定义head2.phtml 替换现有的head.phtml

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多