Blog: PHP

The strengths (and limits) of Joomla's overrides

Published

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:

JHtml::_('bootstrap.tooltip');

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:

function pagination_list_render($list)
{
return \JLayoutHelper::render('joomla.pagination.list', array('list' => $list));
}

function pagination_item_active(&$item)
{
return '<a href="' . $item->link . '" class="item-nav">' . $item->text . '</a>';
}

function pagination_item_inactive(&$item)
{
return '<span class="pagenav">' . $item->text . '</span>';
}

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.

Blog

View all
JS

TinyMCE 5: Creating a custom Dialog Plugin (and with Custom Button Icons)

Edited: February 6, 2019. The included code also works with the TinyMCE 5 Stable release. I’ve been using TinyMCE for years – I think if I look back in my...

Continue reading...

Game

Just Cause 3 (PS4)

When Just Cause 3 came out back in late 2015, I thought “oh that looks like a lot of fun”. I grabbed it on PS4, and started playing....

Continue reading...

PHP

Learning Laravel: extending Laravel’s Auth workflow without re-coding

There’s a project on the horizon and I thought it would be a great candidate for getting my teeth in to Laravel. So I wanted to do some basic ideas that would...

Continue reading...

JS

Do I still need to use jQuery?

jQuery makes it so easy to start making your website be interactive at the client side. It was easy to learn, powerful, and has a large audience around the world...

Continue reading...

I am the Development Director (and co-owner) at Mity Digital, a Melbourne-based digital agency specialising in responsive web design, custom web development and graphic design.
Mity Digital