Please enable JavaScript to view the comments.
Skip to main content

Smarter Joomla! overrides: keep custom layouts lightweight and update-proof

One of the most common challenges in Joomla development is dealing with custom layout overrides. The core issue? You often end up copying the entire layout file, even when all you really need is to tweak a small part.

The downside is clear: once the original core layout is updated, you have to manually compare your custom layout with the updated one — and apply any necessary changes by hand. That’s tedious and error-prone.

But here’s the thing: in 90–99% of cases, all you really need is to:

  • Add a CSS class
  • Insert a link or a button
  • Slightly modify a heading or field

So why override the full layout?

The Efficient Way: Load the Original Layout and Modify It

Instead of duplicating and maintaining the full layout file, you can load the original Joomla layout inside your override — and apply only the changes you need. This approach greatly reduces maintenance, especially after core or extension updates.

Real-World Example

Let’s say we want to customize the Joomla article layout like this:

  • Replace all <strong> tags with <h3>
  • Add a link from a custom field (for articles in a specific category)
  • Add a custom CSS class
  • Prefix the article title with a custom field value

Instead of copying the entire default.php layout, create a clean custom override:

/templates/your-template/html/com_content/article/default.php

Inside this file, load the core layout and modify its output:

<?php

defined('_JEXEC') or die;

// Check custom fields
if (!empty($this->item->jcfields)) {
    foreach ($this->item->jcfields as $field) {
        // skip fields with empty values
        if ((string)$field->rawvalue === '') {
            continue;
        }
        // Prefix title with custom field value
        if ($field->name === 'title-prefix') {
          $this->item->title = $field->rawvalue . ' - ' . $this->item->title;
        }
      // Add link from custom field in specific category
      if ($field->name === 'custom-link' && $this->item->catid == 7) {
            $this->item->text .= $field->value;
        }
    }
}

// Start output capture
ob_start();

// Load original layout
require JPATH_ROOT . '/components/com_content/tmpl/article/default.php';

// Dump output but replace <strong> to <h3>
echo strtr(ob_get_clean(), [
    '<strong>' => '<h3>',
    '</strong>' => '</h3>',
]);

This keeps your layout lean, clean, and easy to update — since you’re still relying on the original layout structure.

Bonus: Use Regular Expressions for More Power

Using preg_replace() lets you surgically target and modify HTML elements based on attributes, class names, or structure — without touching most of the layout logic.

Final Thought

This technique is a game-changer for Joomla site builders and template developers. It allows you to extend core layouts without the burden of maintaining full override files — and keeps your templates more resilient to future updates.

Save time, reduce errors, and keep your Joomla sites future-proof.