2016-12-05 70 views
0

在我的local.xml文件中,我有標記來覆蓋產品目錄頁面。在麪包屑之前的2columns-left.phtml裏面,我想創建具有動態產品類別標題的自定義類別塊,以及取決於類別名稱的描述和背景顏色。Magento - 將自定義的phtml塊注入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> 

樣板/頁/ HTML /頭/ big_header.phtml:

<h1>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</h1> 

當我將此塊添加到: <reference name="head"> 內容從big_header.phtml顯示正常。

我使用Magento的1.7

回答

1

在你的主題佈局文件夾中創建一個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> 

創建templae作爲

你的主題名稱=>模板文件夾=>頁文件夾=> HTML文件夾=> 頭文件夾=>和big_header.phtml文件

我認爲「樣板」是你的主題名稱。

確保您在管理區域檢查的類別頁面爲Page Layout set to "No layout updates"

目錄=>管理類別=>從左邊欄中選擇您的類別=>轉到自定義設計選項卡和頁面佈局字段。

沒有必要使用$this->getChildHtml('big_header');

+0

謝謝你的工作解決方案。蘇曼先生,我有最後一個問題。如何在breadcrumb之前只在catalog_category_view上添加自定義塊? http://prntscr.com/dgx5o7 –

0

Magento會用core/text_list塊(如content),將自動地使所有子元素。 Unforutnatley,root不是其中之一。您需要編輯您的模板page/2columns-left.phtml並添加一個調用到它的塊 - 即

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

+0

我已經改變那個local.xml:' <引用名稱= 「根」> <操作方法= 「setTemplate」> <參考name =「content」> '並將<?php echo $ this-> getChildHtml('big_header')?>添加到2列 - 左 –

+0

是,現在你需要調用你的'page/2columns-left.phtml'文件中的元素。 –

+0

但沒有任何變化 - 這個自定義塊仍然沒有出現 –