2012-03-12 50 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