Magento: Custom Page Templates in CMS Layout Dropdown
![]()
Creating new page templates is as easy as duplicating and editing the files in /template/page/. However, you can add as many new ones as you want, but no new ones will show up in the Layout dropdown when selecting a template to use for a specific CMS page.
The solution: Create your own simple module to add your templates. This should only take you 5 minutes if you know what you are doing with custom modules.
Step 1: Create Your Module Config File
Create this file: /app/code/local/YOURMODS/CmsTemplates/etc/config.xml and put the following code in, modifying it to suit your templates:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <config> <global> <cms> <layouts> <cms_template_1> <label>Home Page</label> <template>page/2columns-right-home.phtml</template> </cms_template_1> <cms_template_2> <label>Category Listing</label> <template>page/category_listing.phtml</template> </cms_template_2> <cms_template_3> <label>4 Column</label> <template>page/4columns.phtml</template> </cms_template_3> </layouts> </cms> </global> </config> |
Step 2: Enable Your Module
Edit or create the following file: /app/etc/modules/YOURMODS_All.xml. Put the following code in that file:
1 2 3 4 5 6 7 8 | <config> <modules> <YOURMODS_CmsTemplates> <active>true</active> <codePool>local</codePool> </YOURMODS_CmsTemplates> </modules> </config> |
Clear Magento’s cache if you don’t have caching turned off, and edit a CMS Page. You should now see your new templates listed in the Layout dropdown under the Custom Design tab.
Thanks for the tutorial. I just tried it but am not having any luck. The module shows up in System Config –> Advanced, but when I go to edit CMS Pages the list of templates does not display in the layout dropdown menu. Any suggestions?
Edit: I just tried this again but literally using YOURMODS_CmsTemplates instead of using TERRYMODS_cmstemplates, and it worked! If you know why, do tell!
Terry,
It’s difficult to know what to suggest when I can’t see your code. There are so many variables. Make sure to triple-check that everything is correct, and in the correct place. So, in other words - welcome to custom modules in Magento
Just keep playing with it - try things. Put errors in the xml on purpose - make sure it’s reading the files.
I’m assuming that the issue then was that you didn’t modify another occurance of “YOURMODS_CmsTemplates” maybe? I can’t be sure without having seen all of your code.
@Terry did you make sure that your directory is named TERRYMODS as well? also the XML file in /app/etc/modules must be TERRYMODS_All.xml…
@josh Pratt thanks for this tutorial, quite useful. However, How would I go about creating a totally custom layout for the Home page. I’d like to keep the default layout in page.xml but I want to add another layout specific only to the home page where I specify some home page specific CMS blocks and code blocks in the left/right columns and above the footer… is there a chance you could write a tut about this? Thanks!
Robert,
Well, you can certainly create a page template (and use it for the home page only) and call the CMS blocks right in the code (or from within the Home Page CMS content in the admin. You don’t have to do anything complicated to do that.
Hi Josh, thanks for your comment reply.
Meanwhile, I’m figuring out what I can do with these XML layout files and phtml template and all the template functionality built into Magento. Maybe, the confusing thing is that you can do the same thing in many ways…
Robert,
Yes, there are definitely a whole bunch of ways to do the same thing. There are certainly better ways than others - but finding the better/best way can be difficult, especially for someone who isn’t a complete PHP pro (like me). Just keep trying things and don’t be afraid to experiment. Forums and IRC are great resources if you get stuck.