11

I discovered after upgrading Magento that the core Mage_Page's config.xml had been manually edited, and now I'm looking to change the XML in a way that doesn't overwrite core.

Here is an example of the core XML:

<config>
    <modules>
        <Mage_Page>
            <version>1.6.0.0</version>
        </Mage_Page>
    </modules>
    <global>
        <models>
            <page>
                <class>Mage_Page_Model</class>
            </page>
        </models>
        <blocks>
            <page>
                <class>Mage_Page_Block</class>
            </page>
        </blocks>
        <page>
            <layouts>
                <empty module="page" translate="label">
                    <label>Empty</label>
                    <template>page/empty.phtml</template>
                    <layout_handle>page_empty</layout_handle>
                </empty>
                <one_column module="page" translate="label">
                    <label>1 column</label>
                    <template>page/1column.phtml</template>
                    <layout_handle>page_one_column</layout_handle>
                    <is_default>1</is_default>

I'm looking to add another layout, like one_column or empty. Overwriting config.xml with app/code/local/Mage/Page/etc/config.xml didn't seem to work, how should I go about doing it without touching core?

5

Create a module with a dependency on Mage_Page and add the new layout in your own config:

app/etc/modules/My_Layout.xml

<?xml version="1.0"?>
<config>
    <modules>
        <My_Layout>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Page />
            </depends>
        </My_Layout>
    </modules>
</config>

app/code/local/My/Layout/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <My_Layout>
            <version>1.0.0</version>
        </My_Layout>
    </modules>
    <global>
        <page>
            <layouts>
                <my_layout module="page" translate="label">
                    <label>My Layout</label>
                    <template>page/mylayout.phtml</template>
                    <layout_handle>my_layout</layout_handle>
                </my_layout>
            </layouts>
        </page>
    </global>
    <frontend>
        <layout>
            <updates>
                <my_layout module="My_Layout">
                    <file>my_layout.xml</file>
                </my_layout>
            </updates>
        </layout>
    </frontend>
</config>

app/design/frontend/base/default/layout/my_layout.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <my_layout translate="label">
        <label>All My Layout Pages</label>
        <reference name="root">
            <action method="setTemplate"><template>page/mylayout.phtml</template></action>
            <!-- Mark root page block that template is applied -->
            <action method="setIsHandle"><applied>1</applied></action>
        </reference>
    </my_layout>
</layout>
1

There is the option to add what you need to app/etc/local.xml, just create global/page/layouts node and add what ever you want there. It is not most elegant solution, but it works fine if you do not want to create dedicated module for the purpose of adding a layout template. If you plan to distribute this layout configuration to more shops, then do a local/community module for it.

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.