Thứ Sáu, 17 tháng 5, 2013

Understanding Output Overrides


Introduction

There are many competing requirements for Web designers ranging from accessibility to legislative to personal preferences. Rather than trying to over-parameterise views, or trying to aim for some sort of line of best fit, or, worse, sticking its head in the sand, Joomla! has added the potential for the designer to take over control of virtually all the output that is generated.
Joomla! has been criticized by some for not giving due attention to accessibility or being archaic in their approach to Web standards. However, with 1.5, the responsibility--and, more importantly, the power--to control output is back in the designer's hands.
In addition, except for files that are provided in the Joomla! distribution itself, these methods for customisation eliminate the need for designers and developers to "hack" core files that could change when the site is updated to a new version. Because they are contained within the template, they can be deployed to the Website without having to worry about changes being accidentally overwritten when your System Administrator upgrades the site.
The aim of this tutorial is to introduce the fours areas of the output of Joomla! that are able to be customised by the template designer.
Not interested in all the theory? Jump straight to the cheat sheet below.

MVC 101

MVC can be a scary acronym. It stands for Model-View-Controller and the concepts behind MVC are responsible for the extra flexibility that is now afforded to the designer. While parts of the theory can be rather involved and complicated, the only part that the designer need worry about is the V for View. This is the part that is concerned with output.
Different extensions display output in different ways.
Components, as you already know, are fairly complex and have the ability to display different information in different ways. For example, the Articles Component (com_content) is able to display a single article, or articles in a category, or categories in a section. Each of the ways of representing the different types of data (an article, or a category, or a section) is called a "view" (this comes from our MVC terminology). Most components will have many views. However, the view doesn't actually display the output. This is left up to what we call a "layout" and it is possible for a view to have a variety of layouts.
The main thing to remember here is that components can have multiple views, and each view can have one or more layouts. Each view assembles a fixed set of information, but each layout can display that information in different ways. For example, the Category view in the Articles component assembles a number of articles. These articles could be displayed in a list or in a table (and probably other ways as well). So this view may have a "list" layout and a "table" layout to choose from.
Modules, on the other hand, are very simple. They generally display one thing one way. Modules don't really have views but they do support a layout. Some developers might even support a choice of layout through module parameters.

Template versus Layout

It is very important to distinguish between the role of templates and the role of layouts. The template sets up a structural framework for the page of the Web site. Within this framework are positions for modules and a component to display. What actually gets displayed is governed by the module layout, or the combination of view and layout in the case of the component.
The following image shows the structural layout of a typical Joomla! template (rhuk_milkyway, the default for 1.5). The module positions are displayed by adding tp=1 to the URL (eg, index.php?tp=1). You can clearly see where the module output is contained within the overall template, as well as the main component output starting in the lower-centre region. However, what is actually output in those regions is controlled by the layouts.
Typical Joomla! screenshot with template positions shown.

Ancillary Customisation

While not strictly related to the MVC, there are two other important areas to consider when looking at customising the output of Joomla!.

Ancillary Customisation:Chrome

In addition to layouts, modules have what we call "chrome". Chrome is the style(s) with which a module is to display. Most developers, designers and probably some end-users will be familiar with the different built-in styles for modules (raw, xhtml, etc). It is also possible to define your own chrome styles for modules depending on the designer result. For example, you could design a chrome to display all the modules in a particular position in a fancy Javascript collapsing blind arrangement.
In the screenshot above, you can just make out the names of some of the built-in module chrome used (rounded, none and xhtml).
Note the potential plural. A module or component can have multiple chrome styles applied to it. For example, When the global template setting "preview module positions" is enabled and the page is loaded with ?tp=1 at the end of the url the chrome "outline" is added to all modules and the component. This is in addition to their regular chrome styling. The default chrome settings can be found in the template/system/html/modules.php file and additional chrome styles may be added by adding your own modules.php file to your template.
Chrome styles are functions and are written in this manner:
/*
* foobar (outputs foo before module content and bar after)
*/

function modChrome_foobar($module, &$params, &$attribs)
{
echo '<h1>Foo</h1>';
echo $module->content;
echo '<h1>Bar</h1>';
}
Use $module->content to access the content generated by the module. You may access the module parameters and attributes by using the appropriate variables passed to this function.

Ancillary Customisation:Pagination

The second area has to do with controlling the pagination controls when viewing lists of data. We will look at that in more detail later.

Component Output Types and Layout Overrides

To understand layout overrides we must first understand the file structure of a component. While there are many parts to a component, all fulfilling different roles and responsibilities, we want to look just in the /views/ directory. Here is the partial structure for two of the com_content views:
/components
/com_content
/views
/articles
/tmpl
default.php (this is a layout)
form.php (this is a layout)
view.html.php (this is the view that outputs the HTML)
view.pdf.php (this is the view that outputs the PDF)
/category
/tmpl
blog.php (layout)
blog_items.php (a sub-layout
default.php (layout)
view.html.php (HTML view)
view.feed.php (RSS feed)
So what you see here is that under the /views/ directory, each view is placed in a directory of its own. The content component actually has three other views not shown: archive, frontpage and section.

Output Types

Under the /articles/ directory we have a number of files. There is almost always a file called view.html.php. This is what we call the view file, but there can be more than one depending on the type of output to produce. It has a specific naming convention, view.output_type.php, where the output type can be html, feed, pdf, raw or error (for more information see JDocument in the API reference and look in the directory /libraries/joomla/document/). What this means is when we want html output for this particular view, the view.html.php file is used. When we want the RSS output, the view.feed.php file is used.
The affect of these different output types is most apparent when the Global Configuration setting for Search Engine Friendly URLs is set to Yes, Use Apache mod_rewrite is set to Yes, and Add suffix to URLs is also set to Yes. When this is done, the site URLs will look something like this:
http://domain/sports.html
http://domain/sports.feed
http://domain/sports/rowing.html
http://domain/sports/rowing.pdf
The exact URL will vary depending on how you set up your site but the point here is to show that sports.html will use the category view's view.html.php file to, and that sports.feed will display the RSS feed for the category using view.feed.php. It should be noted that you cannot currently customise feed or PDF output types. However, you can customise the html output type and this is where layouts come into play.

Layouts

Under the view directory there is a /tmpl/ directory in which the layout files reside. Each PHP file in this directory represents a layout. For example, article/tmpl/default.php is the default layout for an article whereas article/tmpl/form.php is the edit form for an article; category/tmpl/default.php is the default layout for a category whereas category/tmpl/blog.php displays the list of article differently.
The relationship between component views and layout is most plainly seen when adding a new menu item. The next screenshot represents the typical display of the New Menu Item page. Having clicked on Articles (which represents com_content), the tree expands to show the list of views and each layout within the view.
Screenshot of creating a new menu item fro an article.
You will notice that while there are extra files in some of the /tmpl/ directories (like pagebreak.php in the article view), they are missing from the list. This is due to instructions in the XML file for the layout (for example, pagebreak.xml) to hide the layout (or even the view) from the menu item list. However, this is another broad topic which will be covered in another tutorial.
Armed with all that knowledge of how all the parts relate to each other, we are now ready to actually create our layout overrides.

Copying or Creating Layout Files

Layout overrides only work within the active template and are located under the /html/ directory in the template. For example, the overrides for rhuk_milkyway are located under /templates/rhuk_milkyway/html/, for the JA Purity template under /templates/ja_purity/html/ and for Beez under /templates/beez/html/.
It is important to understand that if you create overrides in one template, they will not be available in other templates. For example, rhuk_milkyway has no component layout overrides at all. When you use this template you are seeing the raw output from all components. When you use the Beez template, almost every piece of component output is being controlled by the layout overrides in the template. JA Purity is in between having overrides for some components and only some views of those components.
The layout overrides must be placed in particular way. Using Beez as an example you will see the following structure:
/templates
/beez
/html
/com_content (this directory matches the component directory name)
/articles (this directory matches the view directory name)
default.php (this file matches the layout file name)
form.php
The structure for component overrides is quite simple: /html/com_component_name/view_name/layout_file_name.php. Let's look at a few examples.
The rhuk_milkyway template does not have any layout overrides for any components. If we want to override the default layout for an article, first we need to copy this file:
/components/com_content/views/article/tmpl/default.php
to this location, creating the appropriate directories in the event they don't already exist:
/templates/rhuk_milkyway/html/com_content/article/default.php
If we wanted to override the blog layout in the category view, we would copy this file:
/components/com_content/views/category/tmpl/blog.php
to:
/templates/rhuk_milkyway/html/com_content/category/blog.php
Once the files are copied, you are free to customise these files as much or as little as required or desired. You do not have to honour parameter settings if you don't want to.

Overriding Sub-Layouts

In some views you will see that some of the layouts have a group of files that start with the same name. The category view has an example of this. The blog layout actually has three parts: the main layout file blog.php and two sub-layout files, blog_item.php and blog_links.php. You can see where these sub-layouts are loaded in the blog.php file using the loadTemplate method, for example:
echo $this->loadTemplate('item');
// or
echo $this->loadTemplate('links');
When loading sub-layouts, the view already knows what layout you are in, so you don't have to provide the prefix (that is, you load just 'item', not 'blog_item').
What is important to note here is that it is possible to override just a sub-layout without copying the whole set of files. For example, if you were happy with the Joomla! default output for the blog layout, but just wanted to customise the item sub-layout, you could just copy:
/components/com_content/views/category/tmpl/blog_item.php
to:
/templates/rhuk_milkyway/html/com_content/category/blog_item.php
When Joomla! is parsing the view, it will automatically know to load blog.php from com_content natively and blog_item.php from your template overrides.

Module Layout Overrides

Modules, like components, are set up in a particular directory structure.
/modules
/mod_latest_news
/tmpl
default.php (the layout)
helper.php (a helper file containing data logic)
mod_latest_news.php (the main module file)
mod_latest_news.xml (the installation XML file)
Similar to components, under the main module directory (in the example, mod_latest_news) there is a /tmpl/ directory. There is usually only one layout file but depending on who wrote the module, and how it is written, there could be more.
As for components, the layout override for a module must be placed in particular way. Using Beez as an example again, you will see the following structure:
/templates
/beez
/html
/mod_latest_news (this directory matches the module directory name)
default.php (this file matches the layout file name)
The structure for module overrides is again quite simple: /html/mod_module_name/layout_file_name.php.

Copying or Creating Layout Files

The rhuk_milkyway template does not have any layout overrides for any modules. If we want to override the default layout for Latest News module, we need to copy this file:
/modules/mod_latest_news/tmpl/default.php
to this location, creating the approriate directories in the event they don't already exist:
/templates/rhuk_milkyway/html/mod_latest_news/default.php
You need to take a little care with overriding module layout because there are a number of different ways that modules can or have been designed so you need to treat each one individually.

Module Chrome

Joomla! 1.0 had a number of fixed styles that could display a list of modules in a particular position. These where represented by numbers:
  • 0 (the default) displayed modules in a vertical table
  • 1 displayed them in a horizontal table
  • -1 displayed the raw module output
  • -2 displayed the modules in a XHTML compatible format with the title in a H3 tag.
  • -3 displayed modules in a set of nested DIVs that allowed for rounded-corner techniques
It was a great system except for two things:
  1. Nobody could remember which number was which, and
  2. You couldn't expand on the styles.
Well, in 1.5, the numbers are still recognised, but more commonly the style is represented as a word. As well as that, the syntax for displaying a module position was changed. For example, this snippet displays each module in the left position in the xhtml style:
<jdoc:include type="modules" name="left" style="xhtml" />
The built-in styles that are now available are:
  • table (was 0 and is the default)
  • horz (was 1)
  • none (was -1)
  • xhtml (was -2)
  • rounded (was -3)
  • outline (new - used to preview module positions - see screenshot above)
In the source code, these styles are referred to as "chrome". The default chrome is in the system template of the default Joomla! install:
/templates/system/html/modules.php
This file is maintained by the project so you should never modify it. Your will lose your changes when you upgrade your Joomla! installation.
To create your own chrome, or module styles, create or edit modules.php under the templates /html/ directory. (This is the same directory we have been talking about for component and module layout overrides).
The rhuk_milkyway template provides some extra chrome as an example. (It provides an example style called "slider"). This can be found in the following file:
/templates/rhuk_milkyway/html/modules.php
Creating your own chrome is easy. Let's look at example that displays the module in a Definition List (a set of DL's, DT's and DD's).
Just add the following function to the /html/modules.php file in your default template directory (create it if it does not exist):
/*
* Module chrome that wraps the module in a definition list
*/
function modChrome_dlist($module, &$params, &$attribs)
{ ?>
<dl class="<?php echo $params->get('moduleclass_sfx'); ?>">
<?php if ($module->showtitle != 0) : ?>
<dt>
<?php echo $module->title; ?>
</dt>
<?php endif; ?>
<dd>
<?php echo $module->content; ?>
</dd>
</dl>
<?php
}
We will be calling the style "dlist", so the name of the function needs to be modChrome_dlist.
The function must take the three arguments as shown for the module object, the module parameters, and lastly the $attribs is an array of all the attributes in the jdoc XML tag.
There are three main properties in the module object to be concerned with:
  • showtitle tells you whether to show the title of the module of not
  • title is the title of the module
  • content is the output of the module (from its layout)
This is a very simple case and you can, of course, design more complex styles, possibly using custom atrributes in the XML tag.

Pagination Links Overrides

The final override we will look at is the pagination override. This override can control the display of items-per-page and the pagination links used with lists of information, as shown in the following screenshot.
Typical Joomla! page showing a paginated list.
The rhuk_milkyway template provides a well-commented example for this override. The file is found here:
/templates/rhuk_milkyway/html/pagination.php
When the pagination list is required, Joomla! will look for this file in the default templates. If it is found, it will be loaded and the display functions it contains will be used.
There are four functions that can be used:
pagination_list_footer
This function is responsible for showing the select list for the number of items to display per page.
pagination_list_render
This function is responsible for showing the list of page number links as well at the Start, End, Previous and Next links.
pagination_item_active
This function displays the links to other page numbers other than the "current" page.
pagination_item_inactive
This function displays the current page number, usually not hyperlinked.

Cheat Sheet

Using the rhuk_milkyway template as an example, here is a brief summary of the principles we've looked at.

Customise the Component Output

To override a component layout (for example the default layout in the article view), copy:
/components/com_content/views/article/tmpl/default.php
to:
/templates/rhuk_milkyway/html/com_content/article/default.php
Read more about component output.

Customise the Module Output

To override a module layout (for example the Latest News module using the rhuk_milkyway template), copy:
/modules/mod_latest_news/tmpl/default.php
to:
/templates/rhuk_milkyway/html/mod_latest_news/default.php
Read more about module output.

Add New Module Styles

To add new module styles (chrome), add them to the following file:
/templates/rhuk_milkyway/html/modules.php
Read more about module chrome.

Customise the Pagination Links

To customise the way the items-per-page selector and pagination links display, edit the following file:
/templates/rhuk_milkyway/html/pagination.php
Read more about pagination.

Using Class Suffixes

This tutorial was written for Joomla 1.5, however the differences to Joomla 2.5 are minor.
This tutorial will show you how to use Page, Module, and Menu Class Suffixes in Joomla! to fine-tune the appearance of your site. For the tutorial, we will assume you have the Joomla! 1.5.26 Sample site available.

Background

Joomla! creates HTML pages that use Cascading Style Sheets to control the appearance of the page. This includes things like fonts, colors, margins, and background. The CSS files are part of your template.
When Joomla! creates a page, it creates different CSS classes that are then referenced in the CSS file to specify which style will apply to which parts of the HTML page. These class names are pre-programmed into Joomla!. But Joomla! allows you to modify or add CSS classes by way of the Class Suffix parameters. This lets you fine-tune the appearance of specific pages with no programming and very little work. The best way to understand this is to see specific examples.

When Would You Use a Class Suffix?

Say, for example, that your website contains a number of Section Blog layouts, each for a different Section. If you are happy to have all of these pages styled the same way, then you wouldn't need to use a Page Class Suffix. However, say you want each of these sections styled differently than the others. For example, maybe you want a different background color or image for each different section.
Or say that you want the heading on your front page to look different than the heading on other pages.
In both of these cases, if you modify the styling in your "template.css" file for the standard CSS classes, it will affect all Menu Items that use these CSS classes. For example, if you change the style for the CSS class "componentheading", it will affect all of the Menu Items that use this class.
However, if you add a unique Page Class Suffix to a Menu Item, then Joomla! will create new CSS classes for each individual Menu Item so you can style each one differently.

Page Class Suffix

Before you start, make sure you have the Joomla! sample website available. Also, make sure the default template is set to "rhuk_milkyway" (in the Extensions → Template Manager).

How It Works Without a Page Class Suffix

Before we add a Page Class Suffix, let's see how this pages works without one. In the front end, navigate to Example Pages → Section Blog. In your browser, select the option to view the page source code. For example, in Firefox, press Ctrl+U. In Internet Explorer, select View → Source. In Safari, select View → View Source.
Using the "Find" command, find the first occurrence of the word "componentheading". It should look like the following:
<div class="componentheading">
Browse down the file and find the following tags:
<table class="blog" cellpadding="0" cellspacing="0"> 
<table class="contentpaneopen">
<td class="contentheading" width="100%">
<table class="contentpaneopen">
Note: The following screenshots were made using the free Firefox add-in called Firebug. Firebug allows you to quickly see the relationship between the HTML elements in your source and the text and graphics shown on the page. It is a very handy tool, and you can get it here. For more information, please watch the free video tutorial on using Firebug with Joomla.
The screenshot below shows you the "componentheading" class. It is the page title area above the blog article.
Componentheading class firebug.png
This screenshot shows you the entire "blog" class. This is the outer table into which all of the articles will fit.
Blog class firebug.png
The next screenshot shows you the "contentpaneopen" class for an article heading. This includes the article title and the PDF, Print, and Email icons to the right.
Contentpaneopen class title firebug.png
This screenshot shows you the "contentpaneopen" class for the body of the article. This includes the author and date information as well as the actual article text.
Contentpaneopen class article firebug.png
So this gives us a good understanding of how Joomla! allows us to style the elements on a Section Blog layout. Joomla! writes out these classes as part of the HTML. And the template contains CSS that provides the styling information for these various elements and classes.

Page Class Suffix (No Space)

Now that we see how this works without a Page Class Suffix, let's try it with one. In the back end, navigate to Menus → Example Pages and click on "Section Blog". This should display the "Menu Item: [Edit]" screen for the Section Blog Layout. Click Parameters (System) to show the System Parameters. In the "Page Class Suffix" field enter the value "_myBlogSuffix" and click the Save button.
Now, go back to the front end and again navigate to Example Pages → Section Blog. Notice right away that we lost the styling for the page and article titles. Let's look closer to see why.
Using the browser "Find" command, find the first occurrence of "_myBlogSuffix". It is in a "div" tag and looks like this:
<div class="componentheading_myBlogSuffix">
If you look through the source, you should also see the following classes: blog_myBlogSuffixcontentpaneopen_myBlogSuffix, and contentheading_myBlogSuffix.
By adding the Page Class Suffix, we changed all of these class names. That means that special styling in the CSS file that refers to the "base" class names (like componentheading, blog, and so on) will not be applied, since those classes no longer exist on the page.
Now, you can fix this problem by editing your templates CSS file to add the same styling for the new classes (for example, "componentheading_myBlogSuffix"). But there is a much easier way to do this -- simply by adding a leading space to the parameter.

Page Class Suffix (With a Leading Space)

Again in the back end, go back to Menus → Example Pages → Section Blog. We're going to change the value of the Page Class Suffix. This time we're going to enter in a leading space and call it <space> + "myBlogClass", as shown below.
Page class suffix space.png
Now, go back to the front end and re-display the Example Pages → Section Blog. Notice that our styling is back! Let's look at the HTML source to see what is going on. Open the source and find the first occurrence of "myBlogClass". It should like this:
<div class="componentheading myBlogClass">
Because we put a leading space in the Page Class Suffix, we created a second class instead of changing the name of the first class (which is allowed and supported by all modern browsers). So we didn't break any of the existing CSS styling for this page. (One warning: we need to make sure the new class name is different than any of the other class names used on the page. Otherwise, we might get styling we don't want.)

Add CSS Styling to New Class

At this point, we've created a new CSS class in the HTML to allow for some new styling. Now we need to use this new class to actually change the look of our page. The first thing we need to do is find the applicable CSS file. In this case, it is <joomla_root>/templates/rhuk_milkyway/css/template.css.
Let's say we want to add a background color, but only to this specific Section Blog. (Remember, if we wanted to just change all of the Section Blog pages in our site, we could just change the CSS styling for the base classes, such as "componentheading" or "blog".) We need to do is figure out which area ("componentheading", "blog", or "contentpaneopen") we want to style. Say we just wanted to style the "componentheading" area.
First, let's use the CSS selector "div.myBlogClass" and add the following code to the end of our CSS file:
/* Custom Styling */
div.myBlogClass {
background-color: #FFE4E1; /* mistyrose */
}
The result is that the page heading now has the background color, as shown below.
Div styling example.png
Now this works fine in our example, because the other classes are defined for "table" tags and not "div" tags. But it is normally better to be more specific in our style selector by styling only those elements that have both the desired base class and the new class. For example, let's replace the code above with the following code:
/* Custom Styling */
.blog.myBlogClass {
background-color: #FAFAD2; /* lightgoldenrod */
}
This specifies that the new style will only be applied to elements that have both the "blog" and the "myBlogClass" styles. This gives us the background color over the entire "blog" area, as shown below.
Blog styling example.png
The great thing about creating a new class (with the leading space trick) is that we don't need to copy all of the existing styling for the base classes. We can just focus on the new styling that we want.
Now in this example, we focused on the Section Blog layout. The class names for different components might be different, but the process will be the same. The table below shows some common Joomla! layouts and a list of class names that can have Page Class Suffixes added.
LayoutCSS Class Names Used
Article Layoutcomponentheading, contentpaneopen, contentheading, contentpagetitle
Category Blog, Frontpage Blog, Section Blogcomponentheading, contentpagetitle, blog, contentpaneopen, contentheading, readon, blog_more
Category List, Section Listcomponentheading, contentpane, contentdescription
Contact Categorycomponentheading, contentpane, contentdescription, sectiontablefooter, sectiontableheader, category
Contact Layoutcomponentheading, contentpaneopen, contentheading
So, to sum up what we have learned about using the Page Class Suffix parameter:
  1. Use a leading space to create a new CSS class. This way you don't have to worry about re-doing or breaking existing CSS styles.
  2. Look in the HTML source code to find the locations of the base and new classes.
  3. If desired, use Firebug to see which HTML elements correspond to which areas on the page.
  4. Add custom styling to the end of the "template.css" file, specifying both the name of the desired base class and the custom class in the form .baseclass.customclass as in the example above.

Module Class Suffix

The Module Class Suffix parameter works in the same way as the Page Class Suffix. Let's go through an example using the Latest News module.
In the administrative back end, navigate to Extensions → Module Manager and find the "Latest News" module. Click on it to open it for editing, and enter <space> + "customLatestClass" in the Module Class Suffix parameter field, as shown below:
Module class suffix space.png
Now, navigate to the home page in the front end and view the page source code. The screenshot below was made using the Firebug add-in tool. It shows the home page and the HTML and styling for the customised Latest News module.
Latest news custom class.png
In the upper part of the screen, outlined in light blue, is the "div" element for the module. Below, in the HTML window, we see the HTML as follows:
<div class="moduletable customLatestClass">
and then
<ul class="latestnews customLatestClass">
The "moduletable" and "latestnews" classes are created automatically. The new class, "customLatestNews" was created because we started the Module Class Suffix parameter with a leading space.
Now, let's use our new class to add some custom styling. Again, go to the end of the templates/rhuk_milkyway/css/template.css file and add the following code:
div.customLatestClass {
background-color: #FFFFD2;
}
 
div.customLatestClass h3, ul.customLatestClass, ul.customLatestClass a {
color: #8B4513;
}
Save the file and re-display the home page. It should look like the screenshot below:
Latest news styled.png
The CSS selector div.customLatestClass sets the background color for the entire area. The three selectors div.customLatestClass h3, ul.customLatestClass, ul.customLatestClass a select the font color for the "h3" heading, the bullets ("ul" tag), and the "a" tag, respectively. Note that, if we only wanted to style the "ul" element, we wouldn't need a Module Class Suffix unless we had more than one "Latest News" module. Instead, we could just have defined the CSS using the standard "latestnews" class.

Be careful not to break existing CSS styling

In menus, we need to be careful not to break existing CSS styling.
Let's look at how this works. In the administrative back end, navigate to Extensions → Module Manager and open the Main Menu for editing. Click on the Advanced Parameters. Notice that the Module Class Suffix is set to "_menu", without a leading space.
Now, go to the Home page in the front end and view the source code (or use Firebug). The screenshot below shows the HTML for the Main Menu.
Main menu div.png
Notice that the class is called "module_menu" because of the Module Class Suffix. Also, notice that there is special styling in the "template.css" and "blue.css" files for the "module_menu" class. For example, there is a background image that provides part of the blue border around the menu.
We can confirm this by returning to the back end and changing the Module Class Suffix to blank. Return to the Home page and refresh. Now the Main Menu will show without the special "module_menu" styling, as shown below:
Main menu no suffix.png
This shows an important point. Existing modules, especially menus, may already have CSS styling that depends on Module Class Suffixes. So we need to be careful when making changes.
What if we still wanted to add some special styling just to the Main Menu? One way is to get tricky and add a second CSS class to the existing suffix. To see this, return to the Module Manager in the back end and open the Main Menu for editing. This time, in the Module Class suffix, enter _menu, a space, and then myMenuClass, as shown below:
Module class suffix tricky.png
Now, add the following code to the end of the templates/rhuk_milkyway/css/template.css file:
div.myNewClass {
font-size: 1.2em;
}
Go back to the Home page and notice that now the font in the Main Menu is larger, as shown below.
Main menu custom style.png
If we open Firebug, we can see what the HTML and CSS looks like, as shown below:
Firebug custom menu class.png
By putting a space between the "_menu" and "myNewClass", we added the new class into the HTML. Then, by selecting the new class in the CSS file, we changed the font size.

Menu Class Suffix and Menu Tag ID

All core modules allow you to enter a Module Class Suffix, as discussed above. Menu modules have two additional parameters: Menu Class Suffix and Menu Tag ID. Let's look at what these parameters do.

Menu Class Suffix

The Menu Class Suffix inserts an extra suffix in the class for the unordered list that builds up the menu. If unedited, the class is "menu". If adding "_myMenuClass" under Advanced Parameters → Menu Class Suffix, the new tag will be "menu_myMenuClass".
(This behaviour is only for the Menu Style "List". If choosing "Legacy - Vertical" or "Legacy - Horizontal", the class suffix will be added to the links in the table; this suffix will then be "mainlevel_myMenuClass". When choosing the Legacy Flat List, the suffix will be added to the links (as on the two other Legacy lists), but it will also be added to the ul tag, but as an id rather than a class; the id will be "mainlevel_myMenuClass".)

Menu Tag ID parameter

Now, lets look at the Menu Tag ID parameter. Navigate to the back end, open the Main Menu module for editing, and enter "myTagID" in the Menu Tag ID parameter.
Add the following code to the end of the templates/rhuk_milkyway/css/template.css file:
#myTagID {
list-style-type: square;
}
Now, re-display the Home page to see the change. The bullets for the Main Menu should now appear as squares, as shown below:
Main menu square bullets.png
Finally, we can look at the HTML and CSS in Firebug, as shown below.
Menu tag id code.png
Joomla! has added the attribute id="myTagID" to the "ul" tag for the Main Menu. This allowed us to change the style for this ID. Note that, since this is an "id" attribute, we use the CSS selector#myTagID (with a "#" instead of a ".").

Using Firebug With Your Joomla Website


Firebug is a free add-on program that works with the Firefox web browser. It is tremendously helpful when you are working with Joomla! websites. Firebug lets you:
  • quickly find the exact CSS code that styles any HTML element on a page;
  • quickly identify the HTML code for any element on a page;
  • instantly see the effects of changes to HTML or CSS code on the appearance of the page.
A free, narrated video tutorial called "Using Firebug With Your Joomla! Website" is available at the links below. To play the videos, just click on the links below. To download the video files to your local computer and play them locally, right-click each link in Firefox and select "Save Link As". The contents of each video is as follows:
  • Install Firebug
  • Firebug Layout
  • Inspect Command
  • Find Element From HTML
  • Change CSS
  • Add New CSS
  • Explore Beez Template
  • Beez Font Size Buttons
  • Beez Tableless Design
  • What's Next
  • Module Class Suffixes
  • Menu Styling
  • Module Class Suffix Parameter
  • Page Class Suffix Parameter
  • Add Inline CSS Property
  • Apply Style to New CSS Class
  • Firebug Help Resources
Click here to download both tutorials in one Zip archive. Just unzip the archive and open the SWF files in your browser or SWF player.

Other Languages Available

This tutorial is also available with subtitles in the following languages:
Italian: Part One Part Two

Video Controls

The videos have the following controls:
  • Play / Pause
  • Slider (to quickly position to any point in the video)
  • Volume
  • Table of Contents (pops up)
  • Time Elapsed / Total Time
These are as shown in the picture below.
Video tutorial controls 20090315.png