2

I have a multi-site installation using domain access module and each sub-domain has its own theme. I have a javascript file which is common to all the themes. Right now I've placed the js file inside all the themes folder. Is there a way to place the js file in a common location so that all themes can share it ? Can I use Libraries API module for this purpose ?

2

Yes, you can use the Libraries API for this. The docs explain all of this fairly well. This is best for things that change infrequently.

For my custom Javascript libraries (which I work on continuously), I make module with an instance of hook_library

function mymodule_util_library ()
{
    $path = drupal_get_path("module", "mymodule_util");

    $libraries = array();

    $libraries["mymodule_util"] = array(
        "title" => "MyModule Javascript Utilities", 
        "version" => "0.0",
        "js" => array(
            $path . '/UTIL.js' => array(),
            $path . '/UTIL.HTML5.js' => array(),
            $path . '/UTIL.COLOR.js' => array(),
            $path . '/UTIL.MATH.js' => array(),
        ),

        'weight' => -10,
    );

    return $libraries;
}

Put the module in "site/all/modules" so all of your sites can see it, then enable it on the sites you need.

Then, wherever you need these JS libraries, you use drupal_add_library

drupal_add_library("mymodule_util", "mymodule_util", $every_page);

Typically, this is in a hook_block_view or a preprocess function.

0

MPD's solution is very elegant. But since I'm new to Drupal and I don't know anything about module development (yet), I used a different method. The method I used to solve this problem was :

  1. I placed the js file in the main theme.
  2. I made the remaining themes as sub-themes to the main theme.

I know this is not a very elegant solution but this is an easy solution for newbies in Drupal.

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.