Magento产品在主页上显示网格列

时间:2012-02-08 03:16:12

标签: magento grid themes

尝试在local.xml文件中使用two_column_right模板让主页显示4列网格以显示项目。不幸的是,它采用了我为其他地方的目录页指定的三列网格:/

可能需要在引用主页的标签下插入<update handle="four_column_grid" /> ??

<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">

<four_column_grid>
    <reference name="product_list">
        <action method="setColumnCount">
            <count>4</count>
        </action>
    </reference>
</four_column_grid>

<three_column_grid>
    <reference name="product_list">
        <action method="setColumnCount">
            <count>3</count>
        </action>
    </reference>
</three_column_grid>

 <default>

 <!-- Header -->
        <reference name="header">
             <action method="unsetChild"><name>welcome</name></action>
        </reference>


  <!-- Root -->
  <reference name="root">
   <action method="unsetChild"><name>breadcrumbs</name></action>
  </reference>

  <reference name="footer">         
   <!-- Remove all the other Magento links - "Site Map, Search Terms, Advanced Search, and Contact Us"  -->
   <!-- <action method="unsetChild"><name>footer_links</name></action> -->
  </reference>

 <!-- Right sidebar -->
  <reference name="right">
   <remove name="paypal.partner.right.logo"/>
  </reference>

   </default>


 <catalog_category_default>
     <update handle="three_column_grid" />
 </catalog_category_default>

 <catalog_category_layered>
     <update handle="three_column_grid" />
 </catalog_category_layered> 

</layout>

2 个答案:

答案 0 :(得分:5)

简答:您无法使用布局XML在CMS块的“内部”块上设置值。

在动作控制器中调用loadLayout()时,将处理布局XML,实例化所有块,并执行<action>个节点。但这些区块尚未呈现 调用renderLayout()时,通过调用toHtml()方法来呈现块。

如果块恰好是包含cms/block实例的cms/page(或{{block ...}})实例,则此块将在此时实例化。

在请求流程的这个时刻,所有布局XML <action>节点都已经处理完毕 实际上,您正在引用布局XML中尚不存在的块实例。

作为一种解决方法,您也可以使用布局XML将产品列表块添加到主页。缺点是您无法将其自由放置在CMS块的其他内容中。

<cms_index_index><!-- layout handle for the default homepage action -->
    <reference name="content">
        <block type="catalog/product_list" name="product_list">
            <action method="setTemplate">
                <template>catalog/product/list.phtml</template>
            </action>
            <action method="setCategoryId">
                <catId>51</catId>
            </action>
            <action method="setColumnCount">
                <count>4</count>
            </action>
        </block>
    </reference>
</cms_index_index>

当然,您不仅限于产品列表块。如果您需要将列表放在其他内容中,您可以使用布局XML广告将cms块添加到主页。

答案 1 :(得分:0)

请注意,在扩展rwd主题时,magento ce 1.9+似乎已经发生了变化。您必须为&name; name.after&#39;定义更多块。和&#39;之后&#39;。

<cms_index_index>
    <reference name="content">
        <block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
            <block type="core/text_list" name="product_list.name.after" as="name.after" />
            <block type="core/text_list" name="product_list.after" as="after" />
            <action method="setCategoryId"><catId>3</catId></action>
            <action method="setColumnCount"><count>4</count></action>
        </block>
    </reference>
</cms_index_index>
相关问题