5

I'm trying to get started with Joomla extension development, and am having trouble following along with simple examples.

Where is the Jhtml class defined and/or documented? I see it being used in examples and extensions that come with Joomla, but I can't find any current documentation on it. Existing links into https://api.joomla.org/cms-3/ all appear to be broken, and my attempts to grep the Joomla source have not turned up anything.

Update:

Please tell me whether I understand this correctly. It looks like libraries/classmap.php calls JLoader::registerAlias to dynamically alias the name JHtml to HTMLHelper. I'm unable to find documentation on JHtml because there is no such class.

6

The JHtml class was changed to \Joomla\CMS\HTML\HTMLHelper (/libraries/src/HTML/HTMLHelper.php) since 3.8 as a part of namespacing the core.

I believe you can still use documentation (and API ref) of the old JHTML class.

The best way to learn everything about it - use IDE like PHPStorm for example, and you'll get a lot of useful hints, not to mention class propositions based on partial name typed.

Also what you may put a file like this one: _ide_helper.php in the root of your project to make your transition from <3.8 smoother with IDE.

  • Hey alexandr could add a link to the old documentation to yr post? – jamesgarrett Dec 19 '17 at 9:17
  • Added, but it's almost safe to say that Joomla has almost no documentation for developers, but PHPDocs of the methods are useful. – Alexandr Dec 19 '17 at 12:29
6

As of Joomla 3.8, the majority of classes have been namespaced but with a fallback for when migrating to J4.

So, you can still use JHtml::XXX, but the new approach is:

use Joomla\CMS\HTML\HTMLHelper;

HTMLHelper::_('script', 'path/to/file.js');
HTMLHelper::_('stylesheet', 'path/to/file.css');

You can find the source code for the HTMLHelper class here:

https://github.com/joomla/joomla-cms/blob/staging/libraries/src/HTML/HTMLHelper.php

The code is still the same as it was before, so you can continue reading through the current Joomla documentation for JHtml.

  • But what does this do specifically? Does it add the script to the head of the page? YES IT DOES! – Eoin Jun 10 at 19:52
  • So we should not use JFactory::getDocument(); anymore? – Eoin Jun 10 at 19:54
  • 1
    @Eoin, you can still use it if you want, but I'd suggest against it. HTMLHelper has additional features such as override support. – Lodder Jun 11 at 7:30
  • 1
    Let say you create an extension and load a Javascript file within it using HTMLHelper, users will be able to copy/paste the file into their template directory and make modifications to it if they want. Joomla will automatically load the overridden JS file from the template directory if it exists. – Lodder Jun 11 at 11:28
  • 1
5

Yeah the google links are messed up because of the namespacing and shifting changes. Most of the Joomla core classes are all now in libraries/src here:

https://github.com/joomla/joomla-cms/tree/staging/libraries/src

JHtml is in the HTML folder. The api listing is here:

https://api.joomla.org/cms-3/classes/Joomla.CMS.HTML.HTMLHelper.html

As for "Documentation"... lol.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.