1

I found samples where HTMLHelper was used to load some types of files like stylesheets, scripts and images:

$this->addHeadLink(HTMLHelper::_('image', 'joomla-favicon.svg', '', [], true, 1), 'icon', 'rel', ['type' => 'image/svg+xml']);

The subject code will search for joomla-favicon.svg in the sub-folder images for the current template. For Joomla 4.2 the long answer is /media/templates/site/my_template/images/joomla-favicon.svg. In the same manner:

HTMLHelper::_('script', 'my.js', ['version' => 'auto', 'relative' => true]);

can be used my.js to be loaded from js folder.

What about using HTMLHelper::_ for other file types? Can I have a subfolder named 'files' and force HTMLHelper to use it for a function like addHeadLink? My particular task is to add a head link for Web app manifest, which I can do simply by addHeadLink, but I'm curious if I could use HTMLHelper::_ here.

1 Answer 1

1

No, not out of the box. The method handling this, Joomla\CMS\HTML\HTMLHelper::includeRelativeFiles(), and related methods are protected. You'd have to extend the HTMLHelper class to gain access to the method. It's also worth mentioning that currently this method always looks up files with .min suffix first, even when looking for images (which do not use it at all). This adds additional I/O load, making the method unnecessarily slow. It's actually a bug, it has been reported exactly 2 years ago but hasn't been fixed yet. Anyways, you're better off writing your own method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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