Mohit Jain
Mohit Jain

Reputation: 43949

loading a specific js and css file on a specific page in drupal

page 1 and page 2.

Now for page 1 I want to load page1.js and page1.css and for page2 i want to load page2.css and page2.js.

How to do this in drupal?

Upvotes: 4

Views: 2118

Answers (3)

Kevin
Kevin

Reputation: 13226

You can do this from a module:

function mymodule_init() {
   if (request_uri() == 'path') {
     drupal_add_js( // arguments );
     drupal_add_css( // arguments );
   }
}

http://api.drupal.org/api/function/drupal_add_js

http://api.drupal.org/api/function/drupal_add_css

Upvotes: 2

zerolab
zerolab

Reputation: 836

If you are not too comfortable diving into code, you can try using http://drupal.org/project/css_injector and http://drupal.org/project/js_injector, although Kevin and Ramon Araujo's answers are a more common practice :)

Upvotes: 0

Ramon Araujo
Ramon Araujo

Reputation: 1738

Please try using drupal_add_js and drupal_add_css

Note that you can use php tags inside your page, there you can call drupal functions and so on. Otherwise you can create your own Drupal module and be the master of everything ;)

Hope this helps,

Upvotes: 1

Related Questions