2

I am writing a custom extension, and i wanted to add specific JS and CSS into admin dashboard (on every page), and also different JS/CSS files on front-end...

I have seen many answers, but all of them talk about index.php modifications.. Is not there a simpler method, like worpdress has, something like this phseudo-code:

function AddMyScript(){
    echo '<link rel="stylesheet"..................
    //or $this->AddScript('myCss', 1.01, url......)
}
add_action('wp_head', 'AddMyScript');

also, please add two words about how to implement & call that default.php

5

Here is the documentation: https://docs.joomla.org/J3.x:Adding_JavaScript_and_CSS_to_the_page

If you wish to add different css and js to the front and back of the site then you should use a system plugin and test for which client it is like this:

class plgSystemRandomname extends JPlugin
{

   function onBeforeCompileHead()
   {
       $doc = JFactory::getDocument();
       $app = JFactory::getApplication();

       if ($app->isClient('site')){

         // add all yr scripts and stylesheets from the frontend, eg.
         $doc->addScript('/path/to/script.js');

       } elseif ($app->isClient('administrator')) {

         // add all yr js and css for the backend, eg.
         $doc->addScript('/path/to/different_script.js');

      }
   }

}

Here is the documentation for making a plugin: https://docs.joomla.org/J3.x:Creating_a_Plugin_for_Joomla

Note that isClient came in in J3.7 I think.

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.