如何新增Magento頁面配置

當我們使用Magento後台新增頁面的時候,不管是產品頁面、還是內容頁面都可以選擇頁面的配置。Magento預設的頁面配置有:單欄、雙欄右邊欄、雙欄左邊欄、三欄、空白等。
如果我們今天因為端午節活動,需要新增一個特別的促銷頁面,一個獨特的頁面配置在不影響其他頁面的前提下,最簡單的方法就是新增一個特別的頁面配置。
新增Magento頁面配置其實很簡單,接下來我們將示範如何新增Magento頁面配置。

Step1: 請依底下的路徑找到相關的檔案並修改設定。
/app/code/core/Mage/Page/etc/config.xml
找到<layouts>標籤。
<layouts>
<empty module="page" translate="label">
<label>Empty</label>
<template>page/empty.phtml</template>
<layout_handle>page_empty</layout_handle>
</empty>
<one_column module="page" translate="label">
<label>1 column</label>
<template>page/1column.phtml</template>
<layout_handle>page_one_column</layout_handle>
<is_default>1</is_default>
</one_column>
<two_columns_left module="page" translate="label">
<label>2 columns with left bar</label>
<template>page/2columns-left.phtml</template>
<layout_handle>page_two_columns_left</layout_handle>
</two_columns_left>
<two_columns_right module="page" translate="label">
<label>2 columns with right bar</label>
<template>page/2columns-right.phtml</template>
<layout_handle>page_two_columns_right</layout_handle>
</two_columns_right>
<three_columns module="page" translate="label">
<label>3 columns</label>
<template>page/3columns.phtml</template>
<layout_handle>page_three_columns</layout_handle>
</three_columns>
</layouts>
新增一組配置
<promo_layout module="page" translate="label">
<label>festival</label>
<template>page/festival.phtml</template>
<layout_handle>page_festival</layout_handle>
</promo_layout>
<label>:出現在後台時的標籤名稱
<template>:template所在的路徑及檔案名稱
<layout_handle>:在layout/page.xml 設定時用到的名字
在上面的代碼之中,festival是之出現在layout下拉選單中的標籤名稱,page/festival.phtml是設定template所在的路徑及檔案名稱,當我們要在page.xml指定功能時,要使用page_festival
<layout>
<page_festival translate="label">
將設定寫在這裡
</page_festival>
</layout>
Step2: 新增相對應的template檔案。
以之前的代碼為例,我們應該在下面的路徑新增festival.phtml
/app/design/frontend/yourLayout/yourTheme/template/page
<html>
<head></head>
<body>
<div class="wrapper">
<div class="header"><?php echo $this->getChildHtml('header') ?></div>
<div class="middle">
<div class="col-left"><?php echo $this->getChildHtml('left') ?></div>
<div class="col-main"><?php echo $this->getChildHtml('content') ?></div>
</div>
<div class="footer"><?php echo $this->getChildHtml('footer') ?></div>
</body>
</html>
Step3: 到後台去新增頁面
這時候我會們發現layout下拉選單已經多出了festival這個選項。

更多Magento相關文章請看: Magento教學導覽
我要留言