我正在安装1.9.3 Magento,尝试优化现有应用程序。 有一个自定义主题,它定义了我发现一个大混乱的自定义布局:到处都是重复的文件,完全荒谬的覆盖核心行为,所以我试图整理一切,有一天我成功了,除非有一些非常奇怪的东西发生在最后一步。
我有两个主要的布局文件:local.xml and page.xml
我希望将它们合并到一个文件中。
一切正常,直到我将所有自定义头部行为(在单个部分中清理上传的资源),但一旦合并自定义页面布局,一切都停止工作。
我的意思是:
page.xml
<layout version="0.1.0">
<default>
<label>All Pages</label>
<block type="page/html_head" name="head" as="head">
<action method="addJs"><script>prototype/prototype.js</script></action>
<action ..... more js and css.../>
</block>
<block...../>
</default>
<!-- Custom page layout handles -->
<page_empty ..../>
<page_one_column ..../>
<page_two_columns_left ..../>
....
</layout>
local.xml中剩下的内容
<layout>
<cms_index_index translate="label">
<label>CMS Home Page</label>
<reference name="head"></reference>
</cms_index_index>
<cms_page>
<reference name="content">
<action method="unsetChild">
<alias>cms.wrapper</alias>
</action>
<block type="cms/page" name="cms_page"/>
</reference>
</cms_page>
<catalog_product_view .../>
<catalog_category_layered .../>
<catalog_category_default .../>
</layout>
当我尝试合并两个布局时出现问题:minicart和搜索表单消失,主页中的其他元素变得混乱和重复。
可能的原因是什么?自定义主题中的其他布局文件中没有影响主页或其他类似元素的其他重新定义。有明显的其他布局定义,但每个布局定义都有自己的作用。 我真的不知道在哪里寻找。 现在我可以将这两个文件分开,并且工作正常。
修改: 这是我已经清理过的旧版local.xml。
<?xml version="1.0"?>
<layout>
<default>
<!--CSS and JS Files-->
<reference name="head">
<!-- Modifiche per Casabiancheria-->
<action method="addItem"><type>skin_js</type><script>js/prodotto/product.js</script></action>
<action method="addItem"><type>skin_js</type><script>js/prodotto/configurable.js</script></action>
<action method="addItem"><type>skin_js</type><script>js/prodotto/calendar.js</script></action>
<action method="addItem"><type>skin_js</type><script>js/prodotto/calendar-setup.js</script></action>
<action method="addItem"><type>skin_js</type><script>js/vendor/modernizr.custom.min.js</script></action>
<action method="addItem"><type>skin_js</type><script>js/vendor/selectivizr.js</script></action>
<action method="addItem"><type>skin_js</type><script>js/vendor/matchMedia.js</script></action>
<action method="addItem"><type>skin_js</type><script>js/vendor/matchMedia.addListener.js</script></action>
<action method="addItem"><type>skin_js</type><script>js/vendor/enquire.js</script></action>
<!--
<action method="addItem"><type>skin_js</type><script>js/vendor/app.js</script></action>
-->
<action method="addItem"><type>skin_js</type><script>js/vendor/slideshow.js</script></action>
<action method="addItem"><type>skin_js</type><script>js/vendor/imagesloaded.js</script></action>
<action method="removeItem"><type>skin_js</type><name>js/minicart.js</name></action>
<action method="addItem"><type>skin_js</type><script>js/vendor/minicart.js</script></action>
<action method="addItem"><type>skin_js</type><script>js/prodotto/jquery.elevateZoom-3.0.8.min.js</script></action>
<action method="addItem"><type>skin_js</type><script>js/vendor/msrp.js</script></action>
<action method="addItem"><type>skin_js</type><script>js/vendor/msrp_rwd.js</script></action>
<action method="addItem"><type>skin_js</type><script>js/jquery.flexslider-min.js</script></action>
<action method="addItem"><type>skin_js</type><script>js/main.js</script></action>
<action method="addItem"><type>skin_css</type><name>css/calendar-win2k-1.css</name></action>
</reference>
<remove name="footer_links"/>
<remove name="footer_links2"/>
</default>
<cms_index_index translate="label">
<label>CMS Home Page</label>
<reference name="head"></reference>
</cms_index_index>
<cms_page>
<reference name="content">
<action method="unsetChild">
<alias>cms.wrapper</alias>
</action>
<block type="cms/page" name="cms_page"/>
</reference>
</cms_page>
<!--Product View-->
<catalog_product_view>
<!--CSS and JS Files-->
<reference name="head">
</reference>
<reference name="content">
<!-- <block type="catalog/product_list_related" name="catalog.product.related" as="related_products" template="catalog/product/list/related2.phtml" />-->
<remove name="product.info.extrahint"/>
<remove name="product.reviews"/>
<block type="core/template" name="slider" template="catalog/product/list_session.phtml" />
</reference>
</catalog_product_view>
<catalog_category_layered>
<reference name="head">
<!-- Remove items which the RWD package is not dependent upon -->
<action method="removeItem"><type>skin_js</type><name>js/lib/jquery-1.10.2.min.js</name></action>
</reference>
<reference name="root">
<action method="setTemplate">
<template>page/2columns-left.phtml</template>
</action>
</reference>
<reference name="product_list">
<action method="setColumnCount"><count>3</count></action>
</reference>
</catalog_category_layered>
<catalog_category_default>
<reference name="root">
<action method="setTemplate">
<template>page/2columns-left.phtml</template>
</action>
</reference>
<reference name="product_list">
<action method="setColumnCount"><count>3</count></action>
</reference>
</catalog_category_default>
</layout>
&#13;
编辑2:这是我实际使用page.xml的最终版本
<layout version="0.1.0">
<default translate="label" module="page">
<label>All Pages</label>
<block type="page/html" name="root" output="toHtml" template="page/3columns.phtml">
<block type="page/html_head" name="head" as="head">
<action method="addJs"><script>prototype/prototype.js</script></action>
<action method="addJs"><script>lib/jquery/jquery-1.10.2.min.js</script></action>
<action method="addJs"><script>lib/jquery/noconflict.js</script></action>
<action method="addJs"><script>lib/ccard.js</script></action>
<action method="addJs"><script>prototype/validation.js</script></action>
<action method="addJs"><script>scriptaculous/builder.js</script></action>
<action method="addJs"><script>scriptaculous/effects.js</script></action>
<action method="addJs"><script>scriptaculous/dragdrop.js</script></action>
<action method="addJs"><script>scriptaculous/controls.js</script></action>
<action method="addJs"><script>scriptaculous/slider.js</script></action>
<action method="addJs"><script>varien/js.js</script></action>
<action method="addJs"><script>varien/form.js</script></action>
<action method="addJs"><script>mage/translate.js</script></action>
<action method="addJs"><script>mage/cookies.js</script></action>
<block type="page/js_cookie" name="js_cookies" template="page/js/cookie.phtml"/>
<!-- Remove items which the RWD package is not dependent upon -->
<action method="removeItem"><type>skin_js</type><name>js/ie6.js</name></action>
<!-- Add vendor dependencies -->
<action method="addItem"><type>skin_js</type><name>js/lib/modernizr.custom.min.js</name></action>
<action method="addItem"><type>skin_js</type><name>js/lib/selectivizr.js</name></action>
<action method="addItem"><type>skin_js</type><name>js/lib/matchMedia.js</name></action>
<action method="addItem"><type>skin_js</type><name>js/lib/matchMedia.addListener.js</name></action>
<action method="addItem"><type>skin_js</type><name>js/lib/enquire.js</name></action>
<action method="addItem"><type>skin_js</type><name>js/app.js</name></action>
<action method="addItem"><type>skin_js</type><name>js/lib/jquery.cycle2.min.js</name></action>
<action method="addItem"><type>skin_js</type><name>js/lib/jquery.cycle2.swipe.min.js</name></action>
<action method="addItem"><type>skin_js</type><name>js/slideshow.js</name></action>
<action method="addItem"><type>skin_js</type><name>js/lib/imagesloaded.js</name></action>
<action method="addItem"><type>skin_js</type><name>js/minicart.js</name></action>
<action method="addItem"><type>skin_js</type><script>js/msrp.js</script></action>
<action method="addItem"><type>skin_js</type><script>js/msrp_rwd.js</script></action>
<action method="addItem"><type>skin_js</type><script>js/jquery.flexslider-min.js</script></action>
<action method="addItem"><type>skin_js</type><script>js/main.js</script></action>
<!-- Add stylesheets with no media queries for use in IE 8 and below -->
<action method="addItem"><type>skin_css</type><name>css/styles-ie8.css</name><params/><if><![CDATA[ (lte IE 8) & (!IEMobile)]]></if></action>
<action method="addItem"><type>skin_css</type><name>css/madisonisland-ie8.css</name><params/><if><![CDATA[ (lte IE 8) & (!IEMobile)]]></if></action>
<!-- Add stylesheets with media queries for use by modern browsers -->
<action method="addItem"><type>skin_css</type><name>css/fonts/roboto-condensed/stylesheet.css</name><params/><if><![CDATA[<!--[if (gte IE 9) | (IEMobile)]><!-->]]></if></action>
<action method="addItem"><type>skin_css</type><name>css/styles.css</name><params/><if><![CDATA[<!--[if (gte IE 9) | (IEMobile)]><!-->]]></if></action>
<action method="addItem"><type>skin_css</type><name>css/fonts/fontello3/css/fontello.css</name><params/><if><![CDATA[<!--[if (gte IE 9) | (IEMobile)]><!-->]]></if></action>
<action method="addItem"><type>skin_css</type><name>css/madisonisland.css</name><params/><if><![CDATA[<!--[if (gte IE 9) | (IEMobile)]><!-->]]></if></action>
<action method="addItem"><type>skin_css</type><name>css/flexslider.css</name><params/><if><![CDATA[<!--[if (gte IE 9) | (IEMobile)]><!-->]]></if></action>
<!-- Sets viewport meta tag using text block -->
<block type="core/text" name="head.viewport">
<action method="setText"><text><![CDATA[<meta name="viewport" content="initial-scale=1.0, width=device-width" />]]> </text></action>
</block>
</block>
<block type="core/text_list" name="after_body_start" as="after_body_start" translate="label">
<label>Page Top</label>
</block>
<block type="page/html_notices" name="global_notices" as="global_notices" template="page/html/notices.phtml" />
<block type="page/html_header" name="header" as="header">
<block type="page/template_links" name="top.links" as="topLinks"/>
<block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
<block type="core/text_list" name="top.menu" as="topMenu" translate="label">
<label>Navigation Bar</label>
<block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml">
<block type="page/html_topmenu_renderer" name="catalog.topnav.renderer" template="page/html/topmenu/renderer.phtml"/>
</block>
</block>
<block type="page/html_wrapper" name="top.container" as="topContainer" translate="label">
<label>Page Header</label>
<action method="setElementClass"><value>top-container</value></action>
</block>
<block type="page/html_welcome" name="welcome" as="welcome"/>
</block>
<block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs"/>
<block type="core/text_list" name="left_first" as="left_first" translate="label">
<label>Left Column First (shows above main column on smaller screens)</label>
</block>
<block type="core/text_list" name="left" as="left" translate="label">
<label>Left Column</label>
</block>
<block type="core/messages" name="global_messages" as="global_messages"/>
<block type="core/messages" name="messages" as="messages"/>
<block type="core/text_list" name="content" as="content" translate="label">
<label>Main Content Area</label>
</block>
<block type="core/text_list" name="right" as="right" translate="label">
<label>Right Column</label>
</block>
<block type="page/html_wrapper" name="footer.before" as="footer_before" translate="label">
<label>Page Footer</label>
<action method="setElementClass"><value>footer-before-container</value></action>
</block>
<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml">
<block type="page/html_wrapper" name="bottom.container" as="bottomContainer" translate="label">
<label>Page Footer</label>
<action method="setElementClass"><value>bottom-container</value></action>
</block>
<block type="page/switch" name="store_switcher" as="store_switcher" after="*" template="page/switch/stores.phtml"/>
<block type="page/template_links" name="footer_links" as="footer_links" template="page/template/links.phtml">
<action method="setTitle"><title>Quick Links</title></action>
</block>
<block type="page/template_links" name="footer_links2" as="footer_links2" template="page/template/links.phtml">
<action method="setTitle"><title>Account</title></action>
</block>
<!-- This static block can be created and populated in admin. The footer_links cms block can be used as a starting point. -->
<!--<block type="cms/block" name="footer_social_links">
<action method="setBlockId"><block_id>footer_social_links</block_id></action>
</block>-->
</block>
<block type="core/text_list" name="before_body_end" as="before_body_end" translate="label">
<label>Page Bottom</label>
<block type="page/html_cookieNotice" name="global_cookie_notice" as ="global_cookie_notice" template="page/html/cookienotice.phtml" before="-" />
</block>
</block>
<remove name="footer_links"/>
<remove name="footer_links2"/>
<block type="core/profiler" output="toHtml" name="core_profiler"/>
</default>
<catalog_product_view>
<!--CSS and JS Files-->
<reference name="head">
</reference>
<reference name="content">
<remove name="product.info.extrahint"/>
<remove name="product.reviews"/>
<block type="core/template" name="slider" template="catalog/product/list_session.phtml" />
</reference>
</catalog_product_view>
<catalog_category_layered>
<reference name="head"></reference>
<reference name="root">
<action method="setTemplate">
<template>page/2columns-left.phtml</template>
</action>
</reference>
<reference name="product_list">
<action method="setColumnCount"><count>3</count></action>
</reference>
</catalog_category_layered>
<catalog_category_default>
<reference name="root">
<action method="setTemplate">
<template>page/2columns-left.phtml</template>
</action>
</reference>
<reference name="product_list">
<action method="setColumnCount"><count>3</count></action>
</reference>
</catalog_category_default>
</layout>
&#13;
答案 0 :(得分:1)
你将它们合并到哪个文件中?我假设您正在将所有内容移至local.xml
并从主题中删除page.xml
文件?
这个问题是最后加载local.xml
,因此当您从中替换块时,对page.xml
的任何更新都将丢失。
以下是:
在page.xml
和catalog.xml
之前加载了checkout.xml
。目录和结帐会在标题中添加其他块(例如迷你购物车和搜索表单)。但是,由于最后加载了local.xml
,因此在此过程中会丢失任何预先添加到页面xml中的块,例如catalog.xml
和checkout.xml
。
您需要做的是引用更改所需的块,而不是替换它们。因此,如果您需要将css文件添加到头部,请执行以下操作:
<default>
<reference name="head">
<!-- add blocks and actions here -->
</reference>
</default>
您需要辨别默认值和自定义修改,并通过引用将这些修改移至local.xml
。然后,您可以从主题中删除page.xml
。
或者......你可以将代码分开。
答案 1 :(得分:0)
为什么你甚至为cms_index_index
句柄定义头部参考?
请提供有关清理的更多背景信息并显示完整的文件。对原始local.xml的差异将有助于