Magento – add custom layout template
Current magento version – 1.3.2.4
This is what you need to do to add a new layout template, eg 4 column page layout.
- Copy app/code/core/Mage/Page/etc/config.xml
to app/code/local/Mage/Page/etc/config.xml.
Creating this new file will allow magento core updates to occure without over-writing your changes (you’ll probably have to look out for changes to the core config.xml to megre them into your custom file). - Register your custom module by adding a new file to app/etc/modules, called something like Mage_Local.xml
- In this file add the following code:
<?xml version="1.0"?> <config> <modules> <Mage_Page> //relates to file structure <active>true</active> //set to active <codePool>local</codePool> //tell which folder to look in <depends> //requires the mage core <Mage_Core/> </depends> </Mage_Page> </modules> </config>
- Now create your new template file, easy way is to copy an existing one such as 3columns.phtml (in app/design/frontend/your_package/your_theme/template/page), and give it a name, such as 4columns.phtml
- Register this new template in the config.xml file your created in step 1 by adding your module to the layouts list. For my 4 column example I have added:
<four_columns module="page" translate="label"> <label>4 columns</label> <template>page/4columns.phtml</template> <layout_handle>page_four_columns</layout_handle> </four_columns>
You should now be able to access this new template in the cms->manage pages option in the magento admin backend.
Related posts:
October 27th, 2009 at 3:19 pm
[...] LoonyBlurb – Custom Layout Templates If you work with Magento for very long, you’ll find yourself needing to create custom layout templates. This blog makes that easy to do. [...]
November 9th, 2009 at 5:40 pm
Great post, I have been tearing my hair out over this
November 11th, 2009 at 12:01 pm
I am indeed very grateful for receiving such pertinent information from your post. I do expect for
more essential information for the next post. Keep it up.
November 18th, 2009 at 8:34 pm
Great post! Really helped me out with a project. Thanks!
December 12th, 2009 at 7:53 pm
Very usefull Info Thank You for sharing
January 12th, 2010 at 11:45 am
Hi, i’m new to magento but just attempting this now, i have no app/code/local/Mage/Page/etc/ folder just to be sure do i have to create this or should i have this folder already?
Thanks!
January 12th, 2010 at 12:35 pm
Hi James,
if you don’t have an app/code/local/Mage/Page/etc folder then you need to create one.
Unless you’ve had cause to already modify this section of code then you won’t already have this in the local folder.
Using this local folder allows us to modify sections of the core code or add to it without worrying that it’ll get overwritten during any core updates.
Hope that helps!
January 12th, 2010 at 1:00 pm
Thanks for the fast help loonytoons,
This is now working as expected, helped me out with a project and a deadline!
Really useful post, thanks again
August 20th, 2010 at 6:19 pm
Thanks for this post man. I have a problem though. I followed all the steps and copied and pasted the xml exactly as you have it into a file in the modules folder, but now when i click the dropdown in the backend to assign a template, the dropdown is blank. i see //tell which folder to look in, but which folder are you referring to? Thanks!
August 20th, 2010 at 6:38 pm
nevermind, i figured it out. i can’t figure out how to attached stylesheets and all that via a layout now though. i had been using local.xml, but since switching templates it no longer works.