how can i include a css file for a module

satya - Wednesday, June 08, 2011 2:19:01 PM

you can do the following in your module init


function satya_test_module_init()
{
  drupal_add_css(
      drupal_get_path('module','satya_test_module')
             .'/css/tooltip.css');
  drupal_add_js(
      drupal_get_path('module','satya_test_module')
             .'/js/test.js');
  drupal_add_js(
      drupal_get_path('module','satya_test_module')
             .'/js/tooltip.js');
}

satya - Wednesday, June 08, 2011 2:19:51 PM

You can include images in a subdirectory in your module


document.write('<img id="dhtmlpointer" 
src="/sites/all/modules/satya_test_module/js/arrow2.gif">')

satya - Wednesday, June 08, 2011 2:21:04 PM

You can discover your path

By looking into the view source for your .js file or .css file and find its relative path. This is how I have got the relative path for my module.

satya - Wednesday, June 08, 2011 2:21:25 PM

Example: /sites/all/modules/satya_test_module

Example: /sites/all/modules/satya_test_module

satya - Wednesday, June 29, 2011 11:13:59 AM

Each module could have the following files in its directory


mymodule.info
mymodule.module

satya - Wednesday, June 29, 2011 11:19:10 AM

here is an example .info file


core = 7.x
name = Satya Test Module
description = Use this module to muck
version = "7.x-1.0"

scripts[] = file1.js
scripts[] = sub-dire/file2.js

stylesheets[all][] = file1.css
stylesheets[all][] = sub-dir/file2.css

The directory is relative to the module directory.