2012-03-12 52 views
1

我需要通過佈局更新引用調用將before屬性附加到塊。Magento:使用來自local.xml佈局參考的before/after屬性更新塊位置

這是我local.xml文件:

<?xml version="1.0"?> 
<layout version="0.1.0"> 
    <default> 
     <reference name="content"> 
      <block type="page/html_wrapper" name="content.footer" as="contentFooter" translate="label" after="-"> 
       <label>Content Footer</label> 
       <action method="setElementId"><value>content-footer</value></action> 
       <action method="setElementClass"><value>clear</value></action> 
      </block> 
     </reference> 
    </default> 
    <catalog_category_default> 
     <reference name="breadcrumbs.container"> 
      <action method="unsetChild"><name>category.title</name></action> 
     </reference> 
     <reference name="content"> 
      <block type="catalog/category_view" name="category.title" template="catalog/category/title.phtml" before="content.footer"/> 
     </reference> 
    </catalog_category_default> 
</layout> 

我的問題是,在content塊上創建一個content.footer塊,你可以在管理員指定窗口小部件。我在content.footer塊上使用after="-",所以在我看來,應該總是將它放在內容塊的底部,但情況並非如此。

當您查看目錄類別並將category.products塊插入到content塊中時,它將顯示在content.footer塊的下面。使其工作的唯一方法是,如果我將其重新定義在我的local.xml中,並將所有子塊包含在category.products中,並在before="content.footer"之前設置。

所以我想,爲什麼我不能用在catalog_category_default佈局category.products參考,並設置塊的before屬性,我試過如下:

<reference name="category.products"> 
    <action method="setBefore"><value>content.footer</value></action> 
</reference> 

其中有沒有影響。

我也注意到在Mage_Core_Block_Abstract裏面看到它只是setData()包裝的setAttribute()功能,但想到我會繼續嘗試,仍然一無所獲:

<reference name="category.products"> 
    <action method="setAttribute"><key>before</key><value>content.footer</value></action> 
</reference> 

是否有可能做我想做什麼?之前/之後只適用於相同參考中的塊嗎?

回答

5

佈局更新按佈局更新句柄的順序進行處理。您的區塊被添加到內容的最後,但僅限於default LUH。其他句柄(catalog_product_view,catalog_category_layered等)在該句柄之後進行處理。

如果你真的需要一個內容腳註無處不在,要確保它是內容 div中的最後一件事,你應該將塊添加到節點在default handle和定製模板(直接在page/下,例如page/1column.phtml)通過在getChildHtml('content')呼叫之後添加getChildHtml('your.block')呼叫。這將確保您的塊始終位於內容塊的末尾。

+0

謝謝Ben!我認爲這可能是這種情況。由於我只是_really_需要它在目錄類別頁面中,我將從默認佈局中將其刪除,並在我執行其他更新時更新類別佈局,以便我可以將其強制到底部。 – Kus 2012-03-14 23:03:26