In this post: How to add CSS/JS/an Image to a module backend @lodder shows me how to use HTMLHelper
to add CSS
and JavaScript
.
Previously I had followed the Joomla! documentation https://docs.joomla.org/Adding_JavaScript which suggests using addScript()
In the example by Lodder he is using a form field
and then is using getInput
so I wondered if that makes a difference. I'm keen to learn the right way to do things moving forwards and I know namespacing is what I should be using as a good habit.
My question is instead of using JHhtml
for things like
JHtml::script('jui/jquery.min.js', false, true);
to load jQuery first, can I now do
HTMLHelper::_('script', 'jui/jquery.min.js', false, true);
And secondly, instead of adding to the document head like this:
$document = JFactory::getDocument();
$document->addScript($mediaUrl . '/js/' . $moduleName . ".js",
"text/javascript", true, false, array('version' => 'auto'));
Can I do it like this?
$document = JFactory::getDocument();
$document->HTMLHelper::_('script', 'jui/jquery.min.js', false, true);