skip to Main Content

I’m on a 1.9.3 Magento installation, trying to optimize the existing application.

There is a custom theme, which defines the custom layouts where I found a big mess: duplicated files everywhere, totally absurd overwriting of core behavior, so I tried to tidy up everything, and after one day I succeeded, unless for something really strange that happens in the last step.

I have 2 main layout files: local.xml and page.xml and I wanted to merge them in a single file.

Everything works well, until I put all the custom head behavior (cleaned uploaded assets in the single sections), but everything stops working as soon as I merge the custom pages layout.

What I mean is:

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>

what’s left in 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>

Problems arise as soon as I try to merge the two layouts: minicart and search form disappear, and other elements in the home page gets messed up and duplicated.

What could the possible cause be? There are no other redefinitions in the other layout files in the custom theme that affect the home page or other similar elements. There are obviuosly other layout definitions but each has its own role.
I really dunno where else to search for.
For now I can just leave the two files separated and things work well.

EDIT:
This was the old local.xml that I’ve cleaned up.

<?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>

EDIT 2: This is the final version I’m actually using of 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" />]]>&#10;</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>

2

Answers


  1. why you even define head reference for cms_index_index handle?

    please give more context about your cleanup and show complete files. A diff to original local.xml would help alot

    Login or Signup to reply.
  2. What file are you merging them into? I’m assuming you are moving everything into local.xml and deleting the page.xml file from your theme?

    This problem with this is that local.xml is loaded last, so any updates to page.xml will be lost when you replace blocks from it.

    Here’s how:
    page.xml is loaded before catalog.xml and checkout.xml. Catalog and checkout add additional blocks to the header (such as the mini-cart and search form). But since local.xml is loaded last, any blocks that were added to the page xml beforehand, such as catalog.xml and checkout.xml, are lost in the process.

    What you need to do is reference the blocks you need to make changes to, instead of replacing them. So if you need to add a css file to the head, you do this:

    <default>
        <reference name="head">
            <!-- add blocks and actions here -->
        </reference>
    </default>
    

    You’d need to discern between the defaults and the custom modifications and move those modifications over to local.xml via referencing. Then you could remove page.xml from your theme.

    Or…you can keep the code separate.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search