2012-02-08 27 views
1

home.xmlファイルにtwo_column_rightテンプレートを使用してホームページに項目の表示用の4列グリッドを表示しようとしました。残念ながら、私は他のカタログページで指定した3列のグリッドを使用しています:/ホームページのMagento製品の表示グリッド列

おそらく<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> 
+0

リストブロックをホームページに追加していますか? – Vinai

+1

CMSでは、コンテンツに{{block type = "catalog/product_list" category_id = "51" template = "catalog/product/list.phtml"}}を挿入しました。私は1.3から1.4にアップグレードし、1.4テーマフレームワークに合うようにすべてのテンプレートを作り直しました:/この呼び出しは1.3のレガシーコードです – hotdiggity

答えて

5

短い答え:レイアウトXMLを使用してCMSブロックのブロック「内側」に値を設定することはできません。

アクションコントローラでloadLayout()が呼び出されると、レイアウトXMLが処理され、すべてのブロックがインスタンス化され、<action>ノードが実行されます。しかしブロックはまだレンダリングされていません。
renderLayout()が呼び出されると、ブロックはtoHtml()メソッドを呼び出してレンダリングされます。

ブロックがインスタンスを含むcms/block(またはcms/page)インスタンスの場合、このブロックはこの時点でインスタンス化されます。

リクエストフロー中に、すべてのレイアウト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ブロックを追加できます。

+0

ありがとう!完璧に動作します! :) – hotdiggity

0

rwdテーマを拡張すると、これはmagento ce 1.9+で変更されたようです。 'name.after'と 'after'のブロックをさらに定義する必要があります。

<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> 
関連する問題