2014-04-22 124 views
0

我試圖將我的加密從產品的「內容」視圖移到模板中的自己的部分。與Magento塊和佈局混淆

我的XML看起來是這樣的:

<catalog_product_view translate="label"> 
    <reference name="root"> 
     <action method="setTemplate"> 
      <template>page/2columns-left.phtml</template> 
     </action> 
    </reference> 
    <reference name="content"> 
     <block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml"> 
      ...other blocks... 
      <block type="catalog/product_list_upsell" name="product.info.upsell" as="upsell_products" template="catalog/product/list/upsell.phtml" /> 
      ....other blocks... 
     </block> 
    </reference> 
</catalog_product_view> 

然後,內page/2columns-left.phtml它調用$this->getChildHtml('content')這使得catalog/product/view.phtml,然後該文件中的調用來$this->getChildHtml('upsell_products')製成。

我想要做的就是將'upsell_products'移出主'內容'視圖(因爲它被包裝在模板的右欄中),並將其移動到主要的2列模板中,這樣加售實際上可以坐在2列布局的下方並跨越頁面的整個寬度,而不是被限制在右列。我知道我應該創建一個新的模板,因爲現在這不僅僅是2列,但是設置它的正確方法是什麼?我嘗試了一堆不同的東西,似乎沒有任何工作。我希望我已經包含了所有相關的信息。

回答

1

這就是我所做的。

添加下面的你local.xml中:

<catalog_product_view> 
    <reference name="root"> 
        <block type="core/text_list" name="bottom" as="bottom" translate="label"> 
            <label>bottom</label> 
        </block> 
    </reference> 
    <reference name="bottom"> 
     <block type="catalog/product_list_upsell" name="product.info.upsell" as="upsell_products" template="catalog/product/list/upsell.phtml"> 
      <action method="setColumnCount"><columns>4</columns></action> 
      <action method="setItemLimit"><type>upsell</type><limit>4</limit></action> 
     </block> 
    </reference> 
</catalog_product_view> 

我創建了一個名爲2columns-左下方新的模板,但你可以修改2columns左,如果你想。無論你選擇的模板,你可以調用底部是這樣的:

<div><?php echo $this->getChildHtml('bottom') ?></div> 

主容器COL2左佈局地點此頁腳上方和下方(外)。你會有一些div的樣式,但我會把它留給你。

因此,這已經定義了一個新的結構塊,就像'右'或'左',然後將upsell_products的內容放入其中。

hth,sconnie

+0

謝謝,沒有意識到你必須聲明塊的根,我認爲這就是讓我絆倒。 – Drew