Jure Stern Design & Development

473 words
1 min 34 sec

Custom menu item types in Joomla with the help of xml files

Published on 12 Mar 2012 Comments

Using menu item type layouts is probably one of the most useful techniques when designing custom Joomla templates. If you want to create a custom looking page, which is accessible through a menu link, this is the most appropriate solution.

Alternative article and category layouts

Before we dive in to creating a menu item type for our custom layout, you should have a firm understanding of how alternative layouts work. I covered this in my previous tutorials in Alternative layout for Articles and Categories and Using alternative module layout in Joomla. If you go through these two posts, you won't have any problems creating alternative layouts with the help of xml files.

Creating the files

All files should be in your html folder in your template. Copy the files from their original folders (the procedure is explained in the two links above) and rename them to something meaningful. If you just copy the needed php files for articles and categories you can choose those layouts under the article and category settings. But if you copy the xml files the option to choose the layout disappears.

First you need to rename the xml file to the same name that you choose for the custom layout. In my example the name of the layout is portfolio.xml. The layout will be used in the portfolio section, and I choose to modify the standard Joomla blog layout. The blog layout consists of 4 different php files that you rename + the additional xml file.

Do not forget about the xml file, we have to include it, to take advantage of menu item type
Do not forget about the xml file, we have to include it, to take advantage of menu item type.

Editing the xml file

The xml file mainly consists of the options and values that you see in the settings sidebar under articles and categories. You can leave all the options intact just change the text in the title atribute.

Change the text in the title atribute, what you write here will show in under the menu item type in Joomla administration
Change the text in the title atribute, what you write here will show in under the menu item type in Joomla administration.

Choosing the custom layout from the menu item Type

The name that you enter in the title attribute will be added to the menu item Type option when we create a menu item.

If we create layouts in this way it is very easy for an administrator to pick the layouts when creating menu items. It is also easier to apply alternative layout if you have many items and categories. If they belong to the same menu item they inherit the alternative layout. Lets say that you have a portfolio link on your website and on the first page you have a presentation of your work in a blog format and when you click on one of the works you get to the details article page. You can easily achieve that with Alternative layout overrides and xml files by choosing the menu item type with the custom layout that you created.

I hope you learned and understand Alternative layout overrides, they are an important technique for creating custom Joomla templates.

If you have any questions or comments I'm happy to help you.

About the Author

A picture of Jure Stern

Jure Stern is a Freelance Web Designer & Developer from Slovenia. He worked at a startup in Canada and is now living his dream of being a freelancer.

comments powered by Disqus