简体   繁体   English

Magento-将自定义phtml块注入2columns-left.phtml无法正常工作

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

In my local.xml file, i have markup to overwrite product catalog page. 在我的local.xml文件中,我有标记来覆盖产品目录页面。 Inside of 2columns-left.phtml before breadcrumb i want to create custom category block with dynamic product category title, and description and background color depending on category name. 在面包屑之前的2columns-left.phtml内部,我想创建具有动态产品类别标题,描述和背景颜色(取决于类别名称)的自定义类别块。

Problem is that my custom block not appearing. 问题是我的自定义块没有出现。 local.xml: 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: 样板/页面/html/head/big_header.phtml:

<h1>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</h1>

When i add this block into: <reference name="head"> content from big_header.phtml appear normally. 当我将此块添加到: <reference name="head"> big_header.phtml内容正常显示。

I use Magento 1.7 我使用Magento 1.7

Create a local.xml in your theme layout folder as below. 如下所示在主题布局文件夹中创建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>

Create templae as 将模板创建为

Your theme name => template folder => page folder => html folder => head folder => and big_header.phtml file 您的主题名称=>模板文件夹=>页面文件夹=> html文件夹=>头文件夹=>和big_header.phtml文件

I think "boilerplate" is your theme name. 我认为“样板”是您的主题名称。

Make sure the category page which you are checking is Page Layout set to "No layout updates" in admin area. 确保要检查的类别页面在管理区域中已将Page Layout set to "No layout updates"

Catalog => Manage categories => choose your category from left sidebar => go to custom design tab and Page Layout field. 目录=>管理类别=>从左侧边栏中选择类别=>转到自定义设计选项卡和页面布局字段。

There is no need to use $this->getChildHtml('big_header') ; 无需使用$this->getChildHtml('big_header') ;

Magento uses core/text_list blocks (such as content ) which will automagically render all child elements. Magento使用core/text_list块(例如content )将自动呈现所有子元素。 Unforutnatley, root is not one of these. Unforutnatley, root不是其中之一。 You need to edit your template page/2columns-left.phtml and add a call into it for your block - ie 您需要编辑模板page/2columns-left.phtml并为您的代码块添加一个调用-即

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM