2

EDIT: I decided to rephrase my original question, trying to make it a more general question.

I'm trying two options to achieve the same result, but they turn out differently... I'm working in Magento's DEFAULT package and apart from the two options that I will describe below, everyting else in my configuration is left the same.

Here are my two options:

  • Option 1: Using catalog.xml to apply a change

    I copied app/design/frontend/BASE/default/layout/catalog.xml to app/design/frontend/DEFAULT/default/layout/ and changed line 285 from:

    <block type="catalog/product_view_type_configurable" name="product.info.options.configurable" as="options_configurable" before="-" template="catalog/product/view/type/options/configurable.phtml"/>
    

    into this:

    <block type="catalog/product_view_type_configurable" name="product.info.options.configurable" as="options_configurable" before="-" template="catalog/product/view/type/options/configurable.phtml">
        <block type="core/text_list" name="product.info.options.configurable.renderers" as="attr_renderers" />
        <block type="core/text_list" name="product.info.options.configurable.after" as="after" />
    </block>
    

    This option 1 leads to the following result (the result that I need)

    enter image description here

  • Option 2: Using layout.xml trying to apply the same change

    I have not copied and modified catalog.xml but instead created app/design/frontend/DEFAULT/default/layout/local.xml which is fully working. In this file I have added the following code:

    <layout>
    
        ....
    
        <PRODUCT_TYPE_configurable>
    
            <reference name="product.info.options.configurable">
    
                <block type="core/text_list" name="product.info.options.configurable.renderers" as="attr_renderers" />
                <block type="core/text_list" name="product.info.options.configurable.after" as="after" />
    
            </reference>
    
        </PRODUCT_TYPE_configurable>
    
    </layout>
    

    In my view (please correct me if I'm wrong) this is the only correct way to add the block instances product.info.options.configurable.renderers and product.info.options.configurable.after to the block instance product.info.options.configurable (which in this Option 2 comes from app/design/frontend/BASE/default/layout/catalog.xml).

    This option 2 however leads to the following result (not the result that I need)

    enter image description here

I have checked everything multiple times and this really sums up my two options which lead to different results. I would expect them to lead to the same result (unless the code I added to local.xml is incorrect).

So my question basically comes down to this: Could it be possible that using local.xml leads to another result than doing the exact same thing by using one of the default layout .xml files (e.g. catalog.xml)?

1

I haven't checked for your case, so the answer is more general.

Could it be possible that using local.xml leads to another result than doing the exact same thing by using one of the default layout .xml files (e.g. catalog.xml)?

Yes.

Because the loading order of the files is changed. If you try to <reference> a block which doesn't exist yet, you can't do anything with it. No <action>, no new <block> inside, etc.

To avoid this, you have a few options:

  1. use another layout handle, which is processed later.
  2. <depend> on the module which creates the block, so your file is loaded after catalog.xml.
  3. Use local.xml which is loaded last.
|improve this answer|||||
  • Thank you @Fabian, this explains a lot. Your 3rd option to use local.xml is actually my preferred option. I am trying this in my 2nd option. If local.xml is loaded last, then product.info.options.configurable should already exist when trying to put the two <blocks> inside. Still this doesn't work the way I want to. Does this automatically lead to the conclusion that there must be an error in the code of my local.xml file after all? – ForMat Dec 9 '14 at 15:05
  • IF the block is loaded inside the same layout handle or BEFORE, yes, the block should exist. To know this, the only way is to dig into code with xdebug – Fabian Blechschmidt Dec 9 '14 at 15:25
  • Yesss!! I finally got this figured out and working now, thanks to your answer explaining about the loading order. The problem was actually in another .xml file which was probably loading after catalog.xml, but before local.xml. This file was trying load new <blocks> inside product.info.options.configurable.renderers and product.info.options.configurable.after, and those <blocks> didn't exist until they were created in local.xml. Thank you very much @Fabian! – ForMat Dec 9 '14 at 16:04
  • Note also another difference other than order - local.xml merges it's contents into the theme XML, overwriting any referenced nodes, whereas any layout.xml (eg catalog.xml) file that is found in a theme will completely replace the parent layout of the same name. – benz001 Dec 10 '14 at 1:37
  • This happens everywhere. Names are unique through the whole theme. – Fabian Blechschmidt Dec 11 '14 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.