How Override Layouts Works in Joomla Module

Let's face it, everyone has an opinion about HTML markup especially template designers. Fortunately, changing the output of your module layouts, does not require modifying the original code. A module layout override is possible and preferable, to changing the module layout directly. So let's add and override.

Template Override in Frontend

As you can see in the frontend of our site, now with the help of template override we will simply adding an em tag around the message, that's going to make it appear as italicized text rather than just the plaintext is currently there.

Template html override

So to add the template override we want to go to the templates folder and on this site I'm using the beez_2O template, so click that and you'll notice there is this HTML folder that's in place, if your template does not have an HTML folder, go ahead and create it, because this is where the overrides go.

Create Noida City Folder

So next you'll notice there is a modules.php file and an index.html file in the folder and if you've create this folder it will just be blank, in this case we want to add a new folder for our module. So add a New Folder and call it mod_noidacity and then all we need to do is create the default.php file into this folder and write the following code to override the default.php which is in the modules folder in our root

  1. <?php defined( '_JEXEC' ) or die; ?>
  2. <p><em><?php echo $params->get('message'); ?></em></p>
  3. <ul>
  4. <?php foreach($rows as $row): ?>
  5. <li><?php echo htmlspecialchars($row->place_name); ?></li>
  6. <?php endforeach; ?>
  7. </ul>

Overiding taking place in joomla

So after writing the following code, we can hit Refresh and you'll now notice that it's using the markup from the override rather than the markup from the original module.

Since we've done the layout override rather than touching the original file we can remove and add this override as we please. So if we entirely remove this folder and then hit Refresh again it reverts back to the original markup. So, that way you can make changes to the module output without touching the original source code.

In addition to giving output choices module layouts make it possible for template designers, to override your output without touching the code, always use module layouts, to give your module maximum flexibility with the minimal effort.