Magento – How does PRODUCT_TYPE in catalog.xml work

layoutmagento-1.7

Looking in app/design/frontend/base/default/layout/catalog.xml, I see what appears to be conditional XML based on product type.

<!--
Additional block dependant on product type
-->
    <PRODUCT_TYPE_simple translate="label" module="catalog">
        <label>Catalog Product View (Simple)</label>
        <reference name="product.info">
            <block type="catalog/product_view_type_simple" name="product.info.simple" as="product_type_data" template="catalog/product/view/type/default.phtml">
                <block type="core/text_list" name="product.info.simple.extra" as="product_type_data_extra" translate="label">
                    <label>Product Extra Info</label>
                </block>
            </block>
        </reference>
    </PRODUCT_TYPE_simple>
    <PRODUCT_TYPE_configurable translate="label" module="catalog">
        <label>Catalog Product View (Configurable)</label>
        <reference name="product.info">
            <block type="catalog/product_view_type_configurable" name="product.info.configurable" as="product_type_data" template="catalog/product/view/type/default.phtml">
                <block type="core/text_list" name="product.info.configurable.extra" as="product_type_data_extra" translate="label">
                    <label>Product Extra Info</label>
                </block>
            </block>
        </reference>
        <reference name="product.info.options.wrapper">
            <block type="catalog/product_view_type_configurable" name="product.info.options.configurable" as="options_configurable" before="-" template="catalog/product/view/type/options/configurable.phtml"/>
        </reference>
    </PRODUCT_TYPE_configurable>

How is this logic accomplished? Can these keywords be used in any layout files?

Best Answer

This "logic" are standard layout handles.

They are added here:

\Mage_Catalog_Helper_Product_View::initProductLayout
...
$update->addHandle('PRODUCT_TYPE_' . $product->getTypeId());
$update->addHandle('PRODUCT_' . $product->getId());
...

And yes, they can be used in every layout file. But I recommend to use a local.xml instead of changing the layout.xml files of the core - but this topic is a minefield ;-)

Related Topic