Friday 29 April 2011

How to Create a new layout for specific CMS pages in Magento

Many Of my Magento Developers are getting errors while Creating a new layout for specific CMS Page in magento here is some solution for you all hope you will love to read it.

Magento has a WIKI about this, but honestly, I find it confusing to my friends and it is not really well explained. I really simplified the process with Some more explanation here:

Step 1:
We need to create an extension with its own configuration. This will avoid any issues when updating Magento in the future. What you have to do is create a new “config.xml” in your local extension folders, like this:

app/code/local/SpecialLayouts/RightColumnLayouts/etc/config.xml
I did this path in order to be organized, assuming that I could have Special Layouts with different columns approach. The code for this file should be similar to this:

 
<?xml version="1.0"?>
<config>
 <global>
  <cms>
   <layouts>
    <custom_static_page_name_here>
     <label>Custom static page name</label>
     <template>page/custom-static-page-name.phtml</template>
     <layout_handle>page_custom-static-page-name</layout_handle>
    </custom_static_page_name_here>
   </layouts>
  </cms>
 </global>
</config>

Step 2:
We now need to “activate” this new layout in our environment. To do so, you need to add the module like this:

app/etc/modules/SpecialLayouts_RightColumnLayouts.xml

What is really critical and important on the previous lines is to notice the name of the XML file you need to create. It contains the name of the folder or extension, the underscore and then the name of the specific extension ramification. If you do this differently, Magento will not understand it at all therefore, it will not work.

Now, about the content for this XML file, it should be:
 
<?xml version="1.0"?>
<config>
 <modules>
  <SpecialLayouts_RightColumnLayouts>
   <codePool>local</codePool>
   <active>true</active>
  </SpecialLayouts_RightColumnLayouts>
 </modules>
</config>


Step 3:
Finally, you need to create the actual template page that you have configured in your extension file. You need to use the exact same name for it and it should be located at:

app/design/frontend/default//template/page/custom-static-page-name.phtml

In order to do this template, I recommend using one of the actual templates that are already there for the left or right column, depending on what is needed. It is the easier way to go from an already created phtml structure than trying to do it from the scratch.

Step 4:
This is the easier step in the process, once you have everything on your server, then you should go to your Magento admin, clear your cache and configure your layout on the CMS page needed. To do this, you should go to your CMS record and then click on the “Design” (or “Custom Design” in Magento 1.4.X) tab. In the “Layout” Dropdown, the name you assigned to your should appear now, you select it and save the page. Once again, refresh your cache, and if you go to your new page’s URL, it should show the new layout, so you are done!


 And it is Over hope this will help my Magento Developer Friends
Source

1 comments:

Helder Martins said...

Hello,

I see you have found my blog useful to get some advice on Magento. I hope this can help you and others as well. I would appreciate if you can include a credit reference where you obtained the base of your post and even the code you have posted (www.geekieblog.com).

Thanks and regards.

Post a Comment