在本文中,我’我将介绍我认为是修改任何Magento主题的布局的非常有效的方法。
对于我构建的第一个Magento主题,我将布局文件从默认或空白主题复制到自定义主题布局文件夹中。然后,我将直接修改布局文件,编辑或注释掉目录中的内容,例如:catalog.xml,page.xml,checkout.xml等。…我从来不喜欢直接编辑这些文件,因为我知道,当需要升级到已升级布局文件的较新版本的Magento时,我’d必须将更改合并到新的布局文件中。
有一天,我在研究与布局文件有关的Magento代码,发现了一些代码,使我意识到可以将local.xml文件放在自定义主题中’的布局文件夹,并由Magento自动加载。 (此代码位于fetchFileLayoutUpdates()方法中的/app/code/core/Mage/Core/Model/Layout/Update.php中的第283行上)。
由于Magento’s brilliant tags, it’无需编辑任何默认布局文件就可以执行几乎任何您想做的事情。
在研究代码之前,让’看一下这种方法的优点/缺点:
Here is 的slimmed down, commented local.xml from 上 e of our recent projects:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
<? XML文件 版 ="1.0"?> <layout 版 = “ 0.1.0” > <default> <reference 名称= “头” > <!-Magento出现在/ skin / frontend /<INTERFACE>/<THEME>/js/buyprinting.js for this file --> <action 方法 = “添加项目” ><type> skin_js </type><name>js / buyprinting.js</name></action> <!-- This 去掉 s 的item that was set 在 的page.xml file --> <action 方法 =“除去项目”><type> skin_js </type><name>js / iehover-fix.js</name></action> <!-Magento在/js/prototype / element.storage.js中查找此文件- > <action 方法 = “ addJs” ><name>prototype / element.storage.js</name></action> <action 方法 = “ addCss” ><stylesheet>css / buyprinting.css</stylesheet></action> </reference> <reference 名称= “标题” > <!-这将添加一个CMS块,可以从与标头块关联的模板文件中调用该块。 -> <block 类型=“厘米/块” 名称=“ cms_quick_help”> <action 方法 =“ setBlockId”><block_id> quick_help </block_id></action> </block> <!-- The 去掉 tag 去掉 s 的blocks with 的specified 名称 from 的layout --> <remove 名称= “顶部菜单” /> <remove 名称=“ store_language”/> <remove 名称=“面包屑”/> </reference> <reference 名称= “ top.nav” > <remove 名称=“ catalog.topnav”/> </reference> <reference 名称= “剩下” > <remove 名称=“ left.newsletter”/> <remove 名称=“ left.permanent.callout”/> <remove 名称=“ catalogsearch.leftnav”/> <!-- When you use 的remove tag, it 去掉 s any 块 s with 的specified 名称 from the entire 布局 , regardless of 的context. So, if I 去掉 时事通讯 在 the <default> context and that 名称 is used 在 say 的<catalog_product_view> context, 然后两个块都将被删除。 Because 去掉 operates 上 的global context, 您只能删除一次元素。 Since <remove 名称="时事通讯" /> is 在catalogsearch.xml中被调用时,我们必须将其取消设置,否则会收到错误消息。 The line below 上 ly unsets 的block from 的parent's context, not 的global layout context --> <action 方法 =“ unsetChild”><name>时事通讯</name></action> </reference> <reference 名称= “对” > <!-必须使用remove来删除某些块,而另一些要通过unsetChild来删除。 I've not spent 的time digging 在 to 的code to figure out why --> <remove 名称=“ right.permanent.callout”/> <remove 名称=“ catalog.compare.sidebar”/> <remove 名称=“ left.reports.product.viewed”/> <action 方法 =“ unsetChild”><name>sale.reorder.sidebar</name></action> <action 方法 =“ unsetChild”><name>wishlist_sidebar</name></action> <action 方法 =“ unsetChild”><name>正确查看报告的产品</name></action> <remove 名称=“ cart_sidebar”/> </reference> </default> <!-- CATALOG PAGES --> <catalog_product_view><!-2列-> <reference 名称= “根” > <action 方法 =“ setTemplate”><template>page / 2columns-left.phtml</template></action> </reference> <reference 名称= “内容” > <reference 名称=“ product.info”> <block 类型=“厘米/块” 名称=“ cms_product_info_tabs”> <action 方法 =“ setBlockId”><block_id>product_info_tabs</block_id></action> </block> <block 类型=“目录/ product_view” 名称=“ product.clone_prices” 如 = “价格” 模板=“目录/产品/视图/price_clone.phtml”/> <action 方法 =“ unsetChild”><name>等级价格</name></action> <action 方法 =“ unsetChild”><name>添加</name></action> <remove 名称="添加"/> <reference 名称=“ product.info.options.wrapper.bottom”> <action 方法 =“ unsetChild”><name>product.tierprices</name></action> </reference> </reference> </reference> </ catalog_product_view> </layout> |
我希望本文能为您提供一些如何提高Magento主题技能的指导。如果您对编码布局还有其他建议/评论,请在评论部分中提出建议。
166 评论 s
感谢分享,在这里我找到了另一个Magento布局xml, //www.cloudways.com/blog/customize-magento-modules-through-layout-xml-files/