How to add custom layout template in Magento

May 10, 2012 | In: How to do, Magento, php, web development

Magento provides following types of page layout in default.
1column, 2columns-left, 2columns-right, 3columns, empty, and print. But sometimes we need to change design in layout and we do not want to affect on other pages.
For example, we want to use different layout for all static pages. and we want to use 2columns-left layout style but do not want to change in existing layout.

That time what we have to do?

Yes, we can create our custom layout.

To make your custom layout, follow below steps:

Step-1: Copy app/code/core/Mage/Page/etc/config.xml
to app/code/local/Mage/Page/etc/config.xml.

Creating this new file will allow magento core updates to occur without over-writing your changes.

Step-2: Register your custom module with local. Create a new file to app/etc/modules, called something like Mage_Custom.xml
In this file add the following code:

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

Step-3: Now create your new layout template file, easy way is to copy an existing one such as 2columns-left.phtml (in app/design/frontend/your_package/your_theme/template/page), and give it a name, such as static-pages.phtml

Step-4: Register this new template in the config.xml file your created in step 1 by adding your module to the layouts list. For my static page example I have added:

<static_pages module="page" translate="label">
    <label>static pages</label>
    <template>page/static-pages.phtml</template>
    <layout_handle>static_pages</layout_handle>
</static_pages>

Step-5: When you go to CMS > Pages then you will see this layout at page add/edit time.

That’s it.

How may we help you?

You may also like these related posts

Categories

By Google