2013-05-08 17 views
1

我在getToolbarHtml()後調用list.phtml文件中新創建的引用。但它沒有顯示任何東西。我catalog.xml文件看起來像:getChildHtml()方法在magento中的產品列表頁(類別view.phtml/product list.phtml)中不起作用

<reference name="content"> 
      <block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml"> 
       <block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml"> 
        <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml"> 
         <block type="page/html_pager" name="product_list_toolbar_pager"/> 

         <!-- The following code shows how to set your own pager increments --> 
         <!-- 
          <action method="setDefaultListPerPage"><limit>4</limit></action> 
          <action method="setDefaultGridPerPage"><limit>9</limit></action> 
          <action method="addPagerLimit"><mode>list</mode><limit>2</limit></action> 
          <action method="addPagerLimit"><mode>list</mode><limit>4</limit></action> 
          <action method="addPagerLimit"><mode>list</mode><limit>6</limit></action> 
          <action method="addPagerLimit"><mode>list</mode><limit>8</limit></action> 
          <action method="addPagerLimit" translate="label"><mode>list</mode><limit>all</limit><label>All</label></action> 
         --> 
        </block> 
        <reference name="newreference"> 
         <block type="core/template" name="newreferenceblock" template="newreference.phtml" /> 
        </reference> 

        <action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action> 
        <action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>5</count></action> 
        <action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action> 
        <action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action> 
        <action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action> 
        <action method="setToolbarBlockName"><name>product_list_toolbar</name></action> 

       </block> 
        </block> 

我打電話的內部參考參考,事情是我想創建自己的工具條。那麼它有什麼問題?在list.phtml我打電話給我的參考:

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

請幫助我。

+0

有你在你的系統中創建newreference,基本上是錯誤的,呼叫另一個參考 – Mufaddal 2013-05-08 09:40:10

+0

一個參考是,我已經在** page.xml **文件中創建了它。 – madzacky 2013-05-08 09:45:25

回答

2

替換:

<reference name="newreference"> 
    <block type="core/template" name="newreferenceblock" template="newreference.phtml" /> 
</reference> 

有:

<block type="core/template" name="newreferenceblock" template="newreference.phtml" /> 

,然後使用 'newreferenceblock' 爲塊的名字叫內模板您塊:

<?php echo $this->getChildHtml('newreferenceblock') ?> 
+0

Nupp @zitix,它不適合我...... :(其實我想打電話給list.phtml的參考文件 – madzacky 2013-05-08 10:03:02

+0

但是爲什麼你把放在裏面?發表更多的代碼,很難弄清楚你到底想要什麼 – zitix 2013-05-08 12:54:44

+0

問題解決了,是的,這也是錯誤的,我從那裏刪除了引用到外面,現在它的工作正常:),順便說一句,thanx你的時間@zitix ..! :) – madzacky 2013-05-08 13:56:41

0

把你newreference阻止你的內容塊的一面。

<?php echo $this->getChildHtml('newreference') ?> call this block in one of your layout file something like below its for 2columns-right layout 

<div class="main-container col2-right-layout"> 
     <div class="main"> 
      <?php echo $this->getChildHtml('breadcrumbs') ?> 
      <div class="col-main"> 
       <?php echo $this->getChildHtml('global_messages') ?> 
       <?php echo $this->getChildHtml('content') ?> 
      </div> 
      <div class="col-right sidebar"><?php echo $this->getChildHtml('right') ?></div> 
     </div> 
     <div><?php echo $this->getChildHtml('newreference') ?></div> 
    </div> 
+0

是的,這是工作完全正常,但事情是,我想顯示我的引用** newreference **下面的工具欄/尋呼機,所以我需要在內容塊下調用它。 – madzacky 2013-05-08 10:04:52

+0

好,所以你不需要爲你的需求創建新的引用,只需在工具欄塊下調用你的塊,並刪除你的newreference標籤,並在工具欄塊'<?php echo $ this-> getChildHtml('newreferenceblock')之後的list.phtml文件中刪除。 ?>放這段代碼,你就完成了 – Mufaddal 2013-05-08 10:13:10

+0

我已經這樣做了,但它不起作用。我必須這樣做,因爲我需要在左側邊欄中調用其他塊,所以我正在嘗試創建自己的左側邊欄引用,並且希望顯示傳呼機/工具欄以代替麪包屑。 – madzacky 2013-05-08 10:17:12

0
<reference name="content"> 
      <block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml"> 
       <block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml"> 

        <block type="core/text_list" name="left_custompage" as="left_custompage"> 
         <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/> 
        </block> 
        <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml"> 
         <block type="page/html_pager" name="product_list_toolbar_pager"/> 
         <!-- The following code shows how to set your own pager increments --> 
         <!-- 
          <action method="setDefaultListPerPage"><limit>10</limit></action> 
          <action method="setDefaultGridPerPage"><limit>8</limit></action> 
          <action method="addPagerLimit"><mode>list</mode><limit>10</limit></action> 
          <action method="addPagerLimit"><mode>list</mode><limit>20</limit></action> 
          <action method="addPagerLimit"><mode>list</mode><limit>30</limit></action> 
          <action method="addPagerLimit" translate="label"><mode>list</mode><limit>all</limit><label>All</label></action> 
          <action method="addPagerLimit"><mode>grid</mode><limit>8</limit></action> 
          <action method="addPagerLimit"><mode>grid</mode><limit>16</limit></action> 
          <action method="addPagerLimit"><mode>grid</mode><limit>24</limit></action> 
          <action method="addPagerLimit" translate="label"><mode>grid</mode><limit>all</limit><label>All</label></action> 
         --> 
        </block> 
        <action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action> 
        <action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>5</count></action> 
        <action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action> 
        <action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action> 
        <action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action> 
        <action method="setToolbarBlockName"><name>product_list_toolbar</name></action> 
       </block> 
      </block> 

哪裏custompage是我的自定義模塊,其中我使用的工具條。

5

請使用以下方法(還記得在內容更新裏面catelog.xml你的XML):

<?php echo $this->getLayout()->getBlock('yourblockname')->toHtml(); ?> 
相關問題