Custom Magento CMS page layout
22 Comments 30th MAR 2009 | Posted by Ivan Weiler in Magento

Last week I had a request to add new custom layout for few cms pages in one Magento shop. It’s really useful for different static pages of your shop. First create extension with only config file in it: app/code/local/Inchoo/AdditionalCmsPageLayouts/etc/config.xml
<?xml version="1.0"?>
<config>
<global>
<cms>
<layouts>
<custom_static_page_one>
<label>Custom static page 1</label>
<template>page/custom-static-page-1.phtml</template>
</custom_static_page_one>
</layouts>
</cms>
</global>
</config>
Then activate it: app/etc/modules/Inchoo_AdditionalCmsPageLayouts.xml
<?xml version="1.0"?> <config> <modules> <Inchoo_AdditionalCmsPageLayouts> <codePool>local</codePool> <active>true</active> </Inchoo_AdditionalCmsPageLayouts> </modules> </config>
Add your page/custom-static-page-1.phtml template file (or copy some default one for start) and you’re done
There is also tutorial about this on Magento Wiki. However i don’t like approach of duplicating and overriding Mage files from /local, if it can be avoided, so i decided to write this small and useful example of adding or overriding default Magento settings through separated config files. And yes, Magento values can be overridden this way. Default layouts config can be found in app/code/core/Mage/Cms/etc/config.xml along with used xml code structure, so check it out. Thank you for listening!
To post code in comments, place your code inside [code] and [/code] tags.


















April 8th, 2009 at 8:41
Hi,
Sorry but it doesn’t seems to work for me. I run the 1.3 version. Could I ask for some description (docuemntation?!) of the config.xml file and how to work with them.
Thanks
April 8th, 2009 at 21:14
I tried this as well with Magento v1.2.1.2 and my new template did not show up either using your details described above.
I verified the syntax of my xml files and phtml – no errors.
April 9th, 2009 at 17:20
Hello and thank you for reporting this. I got some troubles while publishing xml in this post.
Anyway, i just updated tag “codepool” to “codePool” in post. I think that may be the problem.
@regges: Sorry, but there is no official Magento documentation. Many things can be found on Magento wiki and forum. My co-worker blog is also nice tutorial resource.
April 20th, 2009 at 18:20
Thanks for this nice tutorial.
Working great!
April 22nd, 2009 at 18:42
@Ivan Weiler
On my local machine (XP), its working but surprisingly its not working onto server (Linux). I have uploaded files properly. Not showing new layout at admin panel.
Any idea?
Thanks in advance!
June 19th, 2009 at 15:53
Since 1.3 version, due to files re-organization you have to replace “cms” tag by “page” like :
June 20th, 2009 at 14:45
Thanks for the info !!
Yes i just checked, <cms> is replaced with <page> in newer versions. I’m sorry your example got stripped
July 9th, 2009 at 23:01
don’t forget this newest addition to config.xml, which i saw in another forum:
page_homepage
July 9th, 2009 at 23:02
uh, tags stripped.. here you go
July 23rd, 2009 at 13:14
I have created custom template and done all the neccessary changes in Config.xml and module.xml file but my layout is not lising in cms page.
anyone can help me out
August 20th, 2009 at 8:36
@Ivan Weiler
I would say simply amazing stuff.
Can you please reply on this thread?
http://www.magentocommerce.com/boards/viewthread/52488/
Thanks a lot for sharing information.
December 13th, 2009 at 6:31
Hey, not trying to oneup you guys or anything but I recently blogged about a nice way to include static pages in Magento.
It doesn’t use any config.xml – just a little shortcode in the CMS, and then you can edit your own phtml file
Check it out!
http://blog.sankhomallik.com/2009/12/11/magento-pages-using-text-editor-not-cms/
January 23rd, 2010 at 22:12
I REALLY appreciate this. It works and is easy to adjust.
January 28th, 2010 at 5:13
Ivan (and anybody else)
Opps… spoke too soon.
It works great on my local dev environment (Win7, Apache 2.2, PHP 5.2) however the same code won’t run on a staging server (Linux, Apache 1.3.33,PHP 5.2). I’ve done the following:
- Checked permissions on the files and dirs. (set to 755 but changed to 777)
- Disabled and re-enabled in “advanced”
- Tried different names, and encodings (default is UTF-8)
- Made sure all files are present.
Ok.. now I’m stumped any thoughts?
Thanks again.
April 13th, 2010 at 5:32
sounds good! I’ll hava a try!
May 24th, 2010 at 0:37
Thanks, this is what i was looking for
June 26th, 2010 at 9:18
John, I faced the exact same thing… were you able to find a solution for this?
June 26th, 2010 at 10:26
if any one is interested, i solved this by doing the following :
In the edit cms page, i chose the default “Empty” layout and added the following the Layout Update XML:
page/home.phtml
my home.phtml now works exactly like it should work in Ivan’s article above.
June 26th, 2010 at 10:27
Sorry! the [code] tag didn't work as expected. here's the xml code
page/home.phtml
August 24th, 2010 at 16:51
Hey, I just wanted to give you a quick heads up because there’s a slight bug with this method as you have it right now.
You need to add a line in config.xml for “layout_handle” (it holds the id used for layout caching). Otherwise, you’re likely to get an error that says,
“Invalid id or tag: must use only [a-zA-Z0-9_]”
if layout caching is turned on.
Here’s an example:
[/code]
Custom static page 1
page/custom-static-page-1.phtml
page_custom_static_page_one
[/code]
Ta, and thanks for the great resource, inchoo!
August 24th, 2010 at 16:52
D’oh! put that wrapper on wrong. Sorry, here’s the right code:
Custom static page 1
page/custom-static-page-1.phtml
page_custom_static_page_one
Sorry ’bout that.
August 24th, 2010 at 16:54
Hmm. it still didn’t format correctly. Check out magentocommerce.com/boards/viewreply/151194/ for the right stuff.