Using the Page Class Suffix in Template Code

Posted on 22 September 2011 by

Joomla Documentation

Sometimes web designers need to access a page class suffix from directly within a template. A common reason to do this is to assign unique styles to individual pages linked from a menu (e.g. to change the dominant color on that page). By default Joomla applies the page class suffixes only to limited areas of a page, which often doesn’t offer enough flexibility. However, by making some simple changes to your template you can take advantage of the cascading nature of stylesheets to apply unique styles to any element on a page.

Load Suffix

First, we need to find out what the page class suffix is for the page we are visiting. To do this, you will need add some code to your template:

  1. Open your template’s index.php file (located in /templates/*template-name*/)
  2. Find thetag in the index.php, near the top area of the template
  3. Above this, insert one of the following code blocks (Either of the following options will work fine in most cases. However they work slightly differently, so in certain cases your needs may dictate a specific choice.)

By Itemid

To load the page class suffix associated with the current Itemid, add this to the top of the index.php file:

$params = $menu->getParams( $active->id );
$pageclass = $params->get( 'pageclass_sfx' );

By Active Menu Item

To load the page class suffix associated with the active menu item, add this to the top of the index.php file: (For sub-pages with no active menu item, this will load the page class suffix for the default menu item.)

$pageclass = "";

if (is_object( $menu )) :
$params = new JParameter( $menu->params );
$pageclass = $params->get( 'pageclass_sfx' );


You should always use htmlspecialchars() in your code before writing something into an HTML attribute, else you open up an attack vector to inject script code into your page.

Insert Suffix

The next step is to use the page class suffix somewhere in the template.

In the Body Tag

The more common method would be to apply the page class suffix as an id or class to thetag. Find thetag (below thetag) and replace it with this:

To Load a Page-Specific Stylesheet

The second method would be to load a stylesheet unique to the page in question. Instead of modifying thetag, look for the stylesheet link within thetags and add the following line directly beneath it:


Using this approach to implement page class suffixes rather than the default approach has several benefits:

  • leaner CSS
  • much greater flexibility in styling any element on the page
  • compliments and simplifies template overrides

Joomla! Documentation


Subscribe or Follow

Sign up for our Newsletter to know the lastest Free Templates, Extensions and more...

Best Free Joomla Templates

Joomla Hosting