Creating a Template Override in Joomla

Creating a Template Override in Joomla

The need to edit core files is a common occurrence in Joomla when you need to make certain changes to the layout and output on your website. A standard example is the Joomla Article page, because, by default, the article’s title is a H2, and needs to be changed into a H1 for SEO purposes.

The easiest way is to directly edit the Joomla files in the Components, Modules, or Plugins folders, but this is very bad practice because any changes you make will be lost when you perform a Joomla update, or if you update any modules or components you have edited.

The safest way is to create an override within your Joomla template’s folder. What this means is that you need to upload the file to your template’s folder, which then forces your website to load that version of the file, rather than the core Joomla file. Therefore, whenever you perform an update to Joomla or an extension, your changes will not be overridden, because updates only affect the files within the Joomla folders.

In this example, we are going to be editing the file that controls Joomla Articles, in order to make it display the correct heading. If you want to perform an override on something different, you will first need to find out which file is controlling it.

 Find the File for you Template Override

The first thing we need to do is find out which file to edit. In most cases it will be self-explanatory: click into the Views folder of the particular extension, and then the file will be in there. In the rare case that you don’t know which file you need to edit, you can find out by checking the URL of your web page, as the URL path will contain the link to the component it is using, so long as you have Search Engine Friendly URLs disabled in Joomla’s Global Configuration. If you have Search Engine Friendly URLs turned off then you can check the URL path by clicking into the Menu Item and examining the Link field.

The Link field in the Menu Item can let you know which file controls it

After checking the link of a standard Joomla Article, it will usually look something like this: www.yoursitename.com/index.php?option=com_content&view=article

What this tells you is that this page is being controlled by the ‘com_content’ component, so this is the folder in which we need to look.

• Open your Components folder and click into com_content. You will see several additional folders, most of which we don’t need. The only folder we need when performing a template override is the Views folder, as this is what controls the content that is displayed, hence the view=article in www.yoursitename.com/index.php?option=com_content&view=article

• Open the Views folder and again you will see more folders! But if we go back and check the link of the page and notice view=article, it is clear that we want to click into the article folder.

• Next we want to open the tmpl folder (an abbreviation of template), and there we have our file: default.php. Make a backup of this on your computer ready to copy into your template folder.

Overriding the Core Joomla File

• Now that we know which file we need to edit, it’s time to copy it into your Joomla template’s html folder, which is where all the template’s override files are stored. Create a new folder using the same structure that it has in the components folder (but without the view or tmpl folders).

In this demonstration we are using the Joomla Article page as an example, and most Joomla templates will already have a template override set up for this. But if yours doesn’t, create this folder path within your html folder: com_content/article, and then copy the default.php file into it.

• We now have a template override set up to edit the Joomla Article page. Open the default.php file and do a test to make sure you set up the override correctly. You could put in a standard <?php echo “test” ?> at the top of your file, but personally I find it easier to simply copy the file’s code into a standard text editor and then delete the code from the file. If you see a blank page, or an error message, then you’ve created a template override. Remember to copy the code back into your php file!

• With the template override all set up and tested, you can perform changes to the file, safe in the knowledge that any Joomla or extension updates will not affect your changes.

Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.