Visual tutorial guide to using the template override mechanism in Joomla - part 2

In part 1 we looked at the Joomla template override system and started looking for the appropriate files, part 2 continues the process.

Look in the modules folder

Here we have located and opened the mod_footer folder, that's the module that produces the footer output on the web pages.

 

Joomla modules folder opened to reveal module folders

 

 

Within the module folder iteslef there are 3 files and a sub-folder called tmpl, within the tmpl folder are two files, the first of these, default.php is the one we need.

default.php

This contains the php script that will generate the footer, it consists of just four lines, as shown below

<?php // no direct access
defined('_JEXEC') or die('Restricted access'); ?>
<div><?php echo $lineone; ?></div>
<div><?php echo JText::_( 'FOOTER_LINE2' ); ?></div>

The first two lines are a security test to ensure that this file cannot be executed directly, then the next two lines are what generate the two lines of the footer.

If you are not a coder or familiar with php don't panic yet - read on!

Copying the module default.php file and where to put it to use template overrides

Using your ftp program, download a copy of /modules/mod_footer/tmpl/default.php and save it on your local computer.

Next we are going to modify that file, then upload it to the server in a new place.

Modifying the default.php file to prevent generation of line 2

Open default.php using a text editor such as notepad or notepad++ if you are working on a PC, or Smultron if working on a Mac. You need to use a 'real' text editor NOT a word processor, that's because word processors insert special codes into the file to indicate things like bold, italic and font changes. Those will cause programs to fail.

Modify the code, there are choices, you can simply delete the line, so you end up with . . .

<?php // no direct access
defined('_JEXEC') or die('Restricted access'); ?>
<div><?php echo $lineone; ?></div>

 

or you can change the line into a comment like this . . .

<?php // no direct access
defined('_JEXEC') or die('Restricted access'); ?>
<div><?php echo $lineone; ?></div>
<div><?php // echo JText::_( 'FOOTER_LINE2' ); ?></div>

The two slashes turn the line into a comment that will be ignored - personally I prefer this method because I can go back and re-instate the code easily if necessary, in addition I often put my initials after the two slashes for identification.

Having edited the file, save it.

 

I purchase Joomla templates from Joomlashack - it's much more cost-effective than writing our own and they work first time! You can visit their website by clicking this image.

Joomlashack logo

 

 

 

Locate the templates folder

Using your ftp program locate the folder templates that is in your Joomla installation. Within the templates folder there will be a number of sub-folders, one for each template that is installed on your Joomla installation.

Looking at the templates folder shown here we can identify the standard Joomla-supplied templates, beezand rhuk_milkyway. In addition there is js_mytemplate. This is a commercial template that has been licenced from Joomlashack for use of the site. Applying a template override to a commercial template it is no different from a template override on one of the standard templates.

 

Joomla templates folder

We are going to apply our template override to the template js_mytemplate so we begin by opening the folder and creating a new sub-folder called html within it. Next create another sub-folder within html with the same name as the module folder that we want to override. See the example screenshot below.

Use all lowercase characters for the foldername and filenames because the systems used on web servers are usually case sensitive.

Upload the modified default.php file

Using your ftp program upload the changed version of default.php making sure that you put it into the sub-folder that you created within the html folder. The new file structure will look like this.

template override in Joomla

Here you can see that within the js_template folder there is a new folder called html, then inside that is mod_footer - same name as the original module, and default.php is within that.

It is essential that these naming conventions are used, otherwise Joomla will not find the template override file and your changes will not be effective.

If you have other modules that have overrides then you will have more than one sub-folder inside html, each of which will have the name that corresponds to the original module sub-folder.

Final testing

Using a web browser, navigate to the page in your Joomla site and check that the second line of the footer has gone, if you have done everything correctly you will see something like this.

overridden template in Joomla

If not, check your work carefully and make sure it's exactly as shown.

 

<< previous page