如何使用XML通过管理面板在Magento中为类别设置块类和模板

时间:2013-02-20 17:06:59

标签: magento templates block categories magento-1.6

我正在尝试覆盖Magento中特定类别的默认模板和块类。

以下代码仅更改模板

<reference name="product_list">
  <action method="setTemplate"><template>catalog/product/list-foobar.phtml</template></action>
</reference>

我还需要将默认的Block Class从Mage_Catalog_Block_Product_List更改为Mage_Catalog_Block_Product_List_Foobar。

这可以在类别的“自定义布局更新”字段中使用XML吗?

我尝试过以下操作,但它也不起作用,

<reference name="product_list">
  <block type="catalog/product_list_foobar" name="product_list" template="catalog/product/list-foobar.phtml" />
</reference>

1 个答案:

答案 0 :(得分:1)

严格回答:     

<CUSTOM_CATEGORY_DISPLAY>
    <reference name="category.products">
        <action method="unsetChild"><child>product_list</child></action>
        <block type="catalog/product_list_foobar" name="product_list" template="catalog/product/list-foobar.phtml" />
    </reference>
</CUSTOM_CATEGORY_DISPLAY>

然后,您可以在要应用这些指令的每个类别的自定义布局更新XML字段中使用<update handle="CUSTOM_CATEGORY_DISPLAY" />

但是,分层导航中涉及的模型和块之间存在一些奇怪/不幸的耦合,因此很可能会出现一些错误的行为。

相关问题