Posted in: Magento

New Template Page Layout In Magento

This has to be one of the greatest tips for ANY Magento developer.  I’ve had to use it MULTIPLE times.  Giving credit where credit is due, this is not my post but originally posted here at TJGamble.com.  Although it says this is for Magento version 1.4.1, it does work in everything I’ve tested up to 1.8.1.0.

Thanks TJ!

It seems as though on every Magento site we do, it is necessary to do a custom home page layout.  I keep finding myself going back to my notes on this, so I thought this information might be useful to others.

  1. Create a new layout file in your themes folder:  app/design/frontend/default/THEME/template/page/homepage.phtml.  For now, just paste the contents from 1column.phtml into this file.  You can customize it later.   Upload this file.
  2. Edit the following file:  app/code/local/Mage/Page/etc/config.xml.  If you don’t have this file, copy it from app/code/core/Mage/Page/etc/config.xml.  You don’t want to edit the file inside of core because this will break your site if you ever upgrade.  Edit the site, and add the following right after the tag “</three_columns>”: 
    <homepage module="page" translate="label">
    <label>Homepage</label>
    <template>page/homepage.phtml</template>
    <layout_handle>page_homepage</layout_handle>
    </homepage>

    Save and upload this file.

  3. In the following file:  app/design/frontend/default/THEME/layout/page.xml, just after the code “</page_three_columns>” add the following:
    <page_homepage translate="label">
    <label>Homepage</label>
    <reference name="root">
    <action method="setTemplate"><template>page/homepage.phtml</template></action>
    <!-- Mark root page block that template is applied -->
    <action method="setIsHandle"><applied>1</applied></action>
    </reference>
    </page_homepage>
  4. In the following file:  app/etc/modules/Mage_All.xml  find the lines that read:
    <Mage_Page>
    <active>true</active>
    <codePool>core</codePool>
    <depends>
    <Mage_Core/>
    </depends>
    </Mage_Page>

    and edit them to read:

    <Mage_Page>
    <active>true</active>
    <codePool>local</codePool>
    <depends>
    <Mage_Core/>
    </depends>
    </Mage_Page>

    Save and upload this file.

  5. Now login to the admin and choose this layout for the page you want to use it.

Have your say