Magento中新建一個佈局檔案(自定義佈局檔案)
阿新 • • 發佈:2019-02-09
magento中預設的佈局檔案為1column.phtml,2columns-left.phtml,2columns-right.phtml,3columns.phtml
其實我們是可以增加自己需要的佈局檔案的。頁面的內容具體要什麼樣子的,這就看自己的需求了。增加magento佈局檔案的方法步驟如下。
1.新建一個佈局檔案newcolumn.phtml 這個newcolumn.phtml根據自己的需要進行設定。大體和預設的幾個佈局檔案的結構一致,呼叫的內容塊一致就ok了。
2.在layout\page.xml中標籤里加以下程式碼,可以參考預設的幾個佈局檔案。<?php /** * 這是一個不要麵包屑的模板(看下面註釋部分) */ ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->getLang() ?>" lang="<?php echo $this->getLang() ?>"> <head> <?php echo $this->getChildHtml('head') ?> </head> <body<?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?>> <?php echo $this->getChildHtml('after_body_start') ?> <div class="wrapper"> <?php echo $this->getChildHtml('global_notices') ?> <div class="page"> <?php echo $this->getChildHtml('header') ?> <div class="main-container col1-layout"> <div class="main" style="padding-top:50px;"> <?php //echo $this->getChildHtml('breadcrumbs') ?> <div class="col-main"> <?php echo $this->getChildHtml('global_messages') ?> <?php echo $this->getChildHtml('content') ?> </div> </div> </div> <?php echo $this->getChildHtml('footer') ?> <?php echo $this->getChildHtml('global_cookie_notice') ?> <?php echo $this->getChildHtml('before_body_end') ?> </div> </div> <?php echo $this->getAbsoluteFooter() ?> </body> </html>
3.在code\core\mage\page\etc\config.xml中這個標籤裡 <page>下的 <layouts>里加入以下程式碼,同樣有其他佈局檔案的寫法,(可以參考其他的佈局寫法)<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>
4.完成上述的幾步之後,清除快取,重新登陸。在Magento後臺選擇layout的時候 就會多一項new cloumn的選項<new_columns module="page" translate="label"> <label>new column</label> <template>page/newcolumn.phtml</template> <layout_handle>page_new_columns</layout_handle> </new_columns>