2

Is there a way to add Javascript to the Joomla Administrator template without creating a child template?

Something equivalent to /media/templates/administrator/atum/css/user.css for Javascript.

2 Answers 2

1

You could create a system plugin that only works in the back-end and loads some JavaScript file.

Probably with something like:

defined('_JEXEC') or die;

use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Plugin\CMSPlugin;

class PlgSystemPluginname extends CMSPlugin
{

  protected $app;

  public function onAfterRender()
  {
    // Quit this when the app is not in the administrator back-end
    if (!$this->app->isClient('administrator'))
    {
      return;
    }

    // Load some JavaScript file
    HTMLHelper::_('script','com_foo/foo.js', 
    ['version' => 'auto', 'relative' => true]);
  }
}
1

-Using the web asset manager from Joomla 4 could help : https://docs.joomla.org/J4.x:Web_Assets

-For a quick solution or test purposes, you may add your javascript in the /media/templates/administrator/atum/js/template.min.js but watch out for updates which might remove the content(you could do a template override then)

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.