1. 程式人生 > >在magento中新建並呼叫一個佈局檔案

在magento中新建並呼叫一個佈局檔案

magento中預設的佈局檔案為1column.phtml,2columns-left.phtml,2columns-right.phtml,3columns.phtml
其實我們是可以增加自己需要的佈局檔案的。頁面的內容具體要什麼樣子的,這就看自己的需求了。增加magento佈局檔案的方法步驟如下。

一、新建一個佈局檔案newcolumn.phtml 這個newcolumn.phtml根據自己的需要進行設定。大體和預設的幾個佈局檔案的結構一致,呼叫的內容塊一致就ok了。

二、在layout/page.xml中標籤里加以下程式碼,可以參考預設的幾個佈局檔案。

<page_new_columns translate="label">
        <label>All new-Column Layout Pages</label>
        <reference name="root">
            <action method="setTemplate"><template>page/newcolumn.phtml</template></action>
            <!-- Mark root page block that template is applied -->
            <action method="setIsHandle"><applied>1</applied></action>
        </reference>
    </page_new_columns>

三、在code/core/mage/page/etc/config.xml中這個標籤裡 <page>下的 <layouts>里加入以下程式碼,同樣有其他佈局檔案的寫法,(可以參考其他的佈局寫法)

    <new_columns module="page" translate="label">
                    <label>new column</label>
                    <template>page/newcolumn.phtml</template>
                    <layout_handle>page_new_columns</layout_handle>
    </new_columns>



完成上述的幾步之後,在Magento後臺選擇layout的時候 就會多一項new cloumn的選項。或者是要通過設定catalog.xml在需要呼叫到該佈局檔案的地方改成相應的標籤就ok了。例如需要在Product view 頁面呼叫該佈局檔案可以修改

        <reference name="root">
            <action method="setTemplate"><template>page/2columns-right.phtml</template></action>
        </reference>
成相應的

        <reference name="root">
            <action method="setTemplate"><template>page/newcolumn.phtml</template></action>
        </reference>
這樣在product view頁面就呼叫了新的佈局檔案了。這樣就給我們前臺設計帶來的更大的方便。可以根據我們的需要來設定magento的前臺顯示結果。