Joomla

The strengths (and limits) of Joomla's overrides

Published October 2nd, 2018

Important: The information in this article is over 12 months old, and may be out of date or no longer relevant.

But hey, you're here anyway, so give it a read see if it still applies to you.

I’ve developed a few sites using Joomla – this is one of them. And one of the best parts of Joomla are the layout overrides.

Nothing irks me more than when a developer decides to update core files of a framework or library – and then wonders why updating to the next version breaks their site.

Joomla knows this, and has given developers the ability to use layout overrides – basically make a copy of core files within the template folder, but edit them to our hearts content. When we go to update Joomla to the next minor version, if we’ve been a good developer, it should all work as expected.

I think this is totally brilliant – the core Joomla layouts are deeeetailed, so I can make my overrides do whatever I need to do.

This site has so many – content layouts, blog layouts, music layouts, tag layouts – but I have so much control over them all. And none of the core Joomla code is changed.

That’s pretty awesome non-destructive editing.

I love it - I can have full control over my layout - and in the instance of this site, was able to get the outputting markup for all needed areas to be in the Bulma-ready format to take advantage of the Bulma CSS framework.

This is really smart, really handy, and really easy to do.

But, there was one issue I had with the pagination markup.

The core Pagination.php file within Joomla’s core library is trying to force me to use Bootstrap on the front end of my website. No. Don’t. Please don’t.

I would run my code – and it would look alright – but I saw a JavaScript error in the Console – and it referenced Bootstrap. In the head of my template, there is no Bootstrap – I’m not using it. So it got me hunting around. View source, and yep, there it is. Go to a blog listing with no pagination and it's gone.

I could disable it on the category list views – but as soon as the number of articles enabled pagination, the error came back.

In the core Pagination class (libraries/src/Pagination/Pagination.php), there is this lovely line:

1JHtml::_('bootstrap.tooltip');
Copied!

Basically this is telling Joomla to use Bootstrap. OK fair enough, it adds functionality for some users – but for a control nut like me, you’re not giving me the ability to (easily) disable it.

From an Admin interface perspective, I’ve got nothing against Bootstrap – but on the front end, I don’t like being forced to use something I don’t want or need for the specific project.

Ideally, a setting within the Joomla setup (or even in my main template php file) to globally enable/disable Bootstrap helpers like this (on the front end) would be perfect.

But instead, I had to create an override called pagination.php in my template’s html folder, and adding the following functions:

1function pagination_list_render($list)
2{
3 return \JLayoutHelper::render('joomla.pagination.list', array('list' => $list));
4}
5 
6function pagination_item_active(&$item)
7{
8 return '<a href="' . $item->link . '" class="item-nav">' . $item->text . '</a>';
9}
10 
11function pagination_item_inactive(&$item)
12{
13 return '<span class="pagenav">' . $item->text . '</span>';
14}
Copied!

This overrides the functions of the Pagination.php file and fixes the issue (i.e. bypasses any calling of the bootstrap.tooltip enabler), but doesn’t follow the same structure of any other override.

So logically, yes, it’s fixed, but seems like there could (or should?) be a better or cleaner way to do this without overriding functions like this.

Given not every one uses Bootstrap, I think the best solution - at the core Joomla or template level - is the ability to disable any calls that would otherwise enable Bootstrap. So that way if someone does want to use it, they can, and Joomla works as expected. But for those who don't want to use it, a simple call at the template (or Joomla config) could just make those calls not output anything to the template. Tools like jQuery Easy are good for setting versions - and disabling Bootstrap - but if I disable Bootstrap, it would be good for Joomla to acknowledge this for the entire front end.

You may be interested in...