Joomla Code Overrides – Customize Default Layouts

Many webmasters use Joomla for their websites because it is open source, free to use, has a lot of extensions and templates and is simple to use. It has also a large community of developers. There are many components, modules and plugins for every possible task. In other words, Joomla is a universal content management system suitable for simple home pages and complex websites. For most purposes it is enough to install a template and few extensions for common needs like displaying ads or Google Analytics. But sooner or later you need to modify the original display or standard layouts. There are two ways to make such modifications. You can either modify the original code or to override Joomla core files.

The first approach by modifying the core files might work but only until you upgrade Joomla. This process may overwrite the modified files and destroy your hard work. The other approach is to create core overrides in the template directory. For every extension Joomla checks HTML directory in the selected template directory where you can copy original files and modify them to suit your needs. Extensions are not only those you have installed, Joomla comes with many plugins, components and modules that are needed for normal operation. Creating overrides is easy. You simply copy files that need to be modified into template/HTML directory. There is a rule on how to create paths for overridden extensions:

TEMPLATE_NAME/html/EXTENSION_NAME/VIEW_NAME/FILE_NAME.php

One example for the overridden display of frontpage managed by the com_content component:

Original file
PATH_TO_JOOMLA/components/com_content/views/frontpage/tmpl/default.php

Override file
TEMPLATE_NAME/html/com_content/frontpage/default.php

Joomla overrides are an elegant way to modify original functionality without modifying core files. Overrides work for built-in and custom installed extensions. Many times where you would like to change the blog display, add advertising code between articles or change any default layout, you don’t have to look for a special extension. All you need is to find the file in Joomla directory where this page element is created and create an override in the template/HTML directory. Of course, you need to be familiar with HTML and PHP code, but this is pretty easy because you will only modify existing code. This way you can customize your Joomla website without installing any extension. The advantage of overrides is that they still work after the Joomla files are updated, but the disadvantage is that they are linked with template. If you change it you need to copy overridden files and modify them for the new design.



Source link