Image2

To add a new page layout (for example to have a different layout for the homepage) to Magento you need to create a new custom module and add some configuration XML.

Create the module as follows.

  1. In the magento source navigate to the folder etc/modules.
  2. Create a file called Bweb_Layouts.xml    (Bweb can be replaced with whatever namespace you want, but it must be consistently used throughout the rest of the code.
  3. Add the following XML code to the file
    <?xml version="1.0"?>
    <config>
       <modules>
          <Bweb_Layouts>
             <active>true</active>
             <codePool>local</codePool>
             <depends>
                <Mage_Page />
             </depends>
          </Bweb_Layouts>
       </modules>
    </config>

This tells Magento to look for an extension module in the local code pool, in the Bweb/Layouts folder.

To configure to module:

  1. Under app/local folder create the folders for Bweb/Layouts/etc
  2. Create a file called config.xml. This file is automatically loaded by Magento when loading a module.
  3. In the config.xml file add the following code.
    <?xml version="1.0"?>
    <config>
      <modules>
        <Bweb_Layouts>
          <version>0.1.0</version>
        </Bweb_Layouts>
      </modules>
      <global>
        <page>
          <layouts>
            <home translate="label">   
              <label>Home</label>
              <template>page/home.phtml</template> 
              <layout_handle>home</layout_handle>
            </home>
            <!-- add more layouts here -->
          </layouts>
        </page>
      </global>
    </config>

The <home> tag is arbitrary but must not duplicate an existing XML tag or there will be a conflict and Magento may end up using the wrong layout. The <template> tag should contain the path of the template file for the layout relative to the ‘template’ folder in your active theme.

With the files in place, clear the cache, and create a new page or edit an existing page. The new layout should now be available in the layout drop down under the Design tab.

Get our news direct to your inbox

Subscribe to our mail list