Magento - 将自定义 phtml 块注入 2columns-left.phtml 不起作用

Magento - injecting custom phtml block into 2columns-left.phtml not working

在我的 local.xml 文件中,我有标记来覆盖产品目录页面。在面包屑之前的 2columns-left.phtml 内,我想创建自定义类别块,其中包含动态产品类别标题、描述和背景颜色,具体取决于类别名称。

问题是我的自定义块没有出现。 local.xml:

   <catalog_category_view>
        <reference name="root">
            <action method="setTemplate">
                <template>page/2columns-left.phtml</template>
            </action>
            <block type="core/template"  name="big_header" before="content" template="boilerplate/page/html/head/big_header.phtml" />
        </reference>
    </catalog_category_view>

boilerplate/page/html/head/big_header.phtml:

<h1>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</h1>

当我将这个块添加到: <reference name="head"> 来自 big_header.phtml 的内容正常显示。

我使用 Magento 1.7

Magento 使用 core/text_list 块(例如 content),它将自动渲染所有子元素。不幸的是,root 不是其中之一。您需要编辑您的模板 page/2columns-left.phtml 并为您的块添加一个调用 - 即

<?php echo $this->getChildHtml('big_header') ?>

在您的主题布局文件夹中创建一个 local.xml,如下所示。

<?xml version="1.0"?>
<layout version="0.1.0">
    <catalog_category_view>
        <reference name="root">
            <action method="setTemplate">
              <template>page/2columns-left.phtml</template> 
            </action>

          </reference>
          <reference name="content">
            <block type="core/template" name="big_header" before="content" template="page/html/head/big_header.phtml" />
        </reference>
    </catalog_category_view>
</layout>

创建模板为

Your theme name => template folder => page folder => html folder => head folder => and big_header.phtml file

我认为 "boilerplate" 是您的主题名称。

确保您正在检查的类别页面在管理区域中是Page Layout set to "No layout updates"

目录 => 管理类别 => 从左侧边栏选择您的类别 => 转到自定义设计选项卡和页面布局字段。

不需要使用$this->getChildHtml('big_header');