该讲我们说说 magento 中 xml 可以做到, 但 phtml 做不到的事情。
1、定义页面结构(1栏,2栏,3栏)
.xml中定义页面结构,.phtml默认没有此功能。在magento中默认的页面结构有1栏结构,2栏结构,3栏结构。这个页面结构就是在xml文件中定义的。
如在:app\design\frontend\base\default\layout\page.xml 中
< default translate = " label " module = " page " >
< label > All Pages </ label >
< block type = " page/html " name = " root " output = " toHtml " template = " page/3columns.phtml " >
这个template=”page/3columns.phtml”就是在定义所有的页面默认使用3栏结构。
在:app\design\frontend\base\default\layout\catalog.xml
< catalog_product_view translate = " label " >
< label > Catalog Product View (Any) </ label >
<!-- Mage_Catalog -->
< reference name = " root " >
< action method = " setTemplate " >< template > page / 2columns - right . phtml </ template ></ action >
</ reference >
< reference name = " right " >
< block type = " catalog/product_compare_sidebar " before = " cart_sidebar " name = " catalog.compare.sidebar " template = " catalog/product/compare/sidebar.phtml " />
< block type = " core/template " name = " right.permanent.callout " template = " callouts/right_col.phtml " >
< action method = " setImgSrc " >< src > images / media / col_right_callout . jpg </ src ></ action >
< action method = " setImgAlt " translate = " alt " module = " catalog " >< alt > Keep your eyes open for our special Back to School items and save A LOT !</ alt ></ action >
</ block >
</ reference >
<!--
Product view
-->
< catalog_product_view translate = " label " >
< label > Catalog Product View (Any) </ label >
<!-- Mage_Catalog -->
< reference name = " root " >
< action method = " setTemplate " >< template > page / 2columns - right . phtml </ template ></ action >
</ reference >
< reference name = " head " >
< action method = " addJs " >< script > varien / product . js </ script ></ action >
< action method = " addItem " >< type > js_css </ type >< name > calendar / calendar - win2k - 1 . css </ name >< params /><!--< if />< condition > can_load_calendar_js </ condition >--></ action >
< action method = " addItem " >< type > js </ type >< name > calendar / calendar . js </ name ><!--< params />< if />< condition > can_load_calendar_js </ condition >--></ action >
< action method = " addItem " >< type > js </ type >< name > calendar / calendar - setup . js </ name ><!--< params />< if />< condition > can_load_calendar_js </ condition >--></ action >
</ reference >