Custom Magento CMS page layout

22 Comments 30th MAR 2009 | Posted by Ivan Weiler in Magento

Custom Magento CMS page layout

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!

If you like what you read, please share it.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Yahoo! Bookmarks
  • Reddit
  • Technorati
  • Twitter
  • StumbleUpon
  • LinkedIn
  • Netvibes
  • NewsVine
  • Sphinn
  • Tumblr
  • Posterous

To post code in comments, place your code inside [code] and [/code] tags.

There are 22 comments (Add Yours +)

  • 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

  • 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.

  • 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.

  • Thanks for this nice tutorial.

    Working great!

  • @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!

  • Since 1.3 version, due to files re-organization you have to replace “cms” tag by “page” like :

  • Thanks for the info !!

    Yes i just checked, <cms> is replaced with <page> in newer versions. I’m sorry your example got stripped :(

  • don’t forget this newest addition to config.xml, which i saw in another forum:

    page_homepage

  • uh, tags stripped.. here you go

  • TestUser Says

    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

  • @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.

  • 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/

  • I REALLY appreciate this. It works and is easy to adjust.

  • 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.

  • Joshua Lee Says

    sounds good! I’ll hava a try!

  • Thanks, this is what i was looking for ;)

  • John, I faced the exact same thing… were you able to find a solution for this?

  • 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.

  • Sorry! the [code] tag didn't work as expected. here's the xml code

    page/home.phtml

  • 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!

  • 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.

  • Hmm. it still didn’t format correctly. Check out magentocommerce.com/boards/viewreply/151194/ for the right stuff.

Leave a Comment

Please wrap all source codes with [code][/code] tags.
Magento Design and Development | Magento SEO | iPhone Application Development Web Application Development with ZEND | WordPress Ecommerce | WordPress development
Sitemap

Inchoo - webappsolutions | 2009