Shopping Basket

 x 

Cart empty


Log In

Find Us Elsewhere

SSL

Forum Search

Keyword

It often happens when you are using a Joomla component or module that you would like to modify the display of the extension in some way.

If the extension uses the MVC (model-view-controller) layout then there is a straightforward way to do this - use template overriding.

How Do I Know If An Extension Supports Template Overriding?

You can tell if an extension supports template overriding by examining the file structure.

If the extension is a component then its site folder should contain a'views' folder, with the templates being stored in sub-folders corresponding to the views that the component supports. The Joomla content component gives a good example of this.

A module does not support different views, so its layout is somewhat simpler. The templates should be stored in a module folder called tmpl.

 

Example - Overriding the Joomla Article Display

For example, the Joomla content component keeps its templates in the folder components/com_content/views/. This contains a set of sub-folders named for the various types of view that Joomla supports: archive, article, category, front-page and section. The templates for the component are stored in a sub-folder called 'tmpl' inside each of these view folders.

To override one of these templates simply place your edited version of in a folder called html in your site template folder. For example, the default layout for a Joomla article is defined in the file

components/com_content/views/article/tmpl/default.php

To override this place your own version in the file

templates/mytemplate/html/com_content/article/default.php

where 'mytemplate' is replaced by the actual name of your template of course. Your version of default.php will have access to the same template variables as the original default.php: you can arrange them in any way that you wish.

Using Template Overriding With Our Extensions

Our own extensions also use the MVC layout, so that you can use template overriding with them. For example our module Featured Items Pro stores its templates in the module folder called tmpl. To override the default template for the module, create a file in your template folder:-

templates/mytemplate/html/mod_featureditems_pro/default.php

Your edited version of the template will have access to all the module template variables. These are stored in an array called $list. The template loops through these displaying each list item in turn. Each list item is an object with the following properties defined:-

  • $item->link - the link to the article
  • $item->author - the article author
  • $item->created - the article creation date
  • $item->modified - the article modification date
  • $item->imageTag - the article image tag
  • $item->text - the article extract
  • $item->readmore - the article readmore (readmore text with link)

Additionally the module parameters can be access through the $params JParameter object. For example, to get the module class suffix use

$params->get('moduleclass_sfx')

So you can see that template overriding allows you the ultimate control over extension layout.

Author Profile