Hi,

I am using Drupal 7.

I have created a module in "sites/all" directory. The module implements one functionality where it lists products. The module directory has my_module.info, my_module.module and my_module.css file. In my_module.info I have added "stylesheets[all][]=my_module.css", so that my stylesheet is used when listing the products.

Now I am creating another site. The same module will be used there as there is no functionality change. Only change I need is the look and feel for the listing. That means the styles defined in my_module.css will change now.

How can I do this? Having single module, but different CSS for multiple sites.

Also please note that, if I have site1, site2 and site3. site1 and site2 can use default css whereas site3 might want to override the css.

Thanks,
Kiran

Comments

nevets’s picture

I would add theme specific files for the other sites.

pushpinderchauhan’s picture

This is straight forward approach to add theme specific files for the other sites.

Also please note that, if I have site1, site2 and site3. site1 and site2 can use default css whereas site3 might want to override the css.

But if you are finding any issue with this, then you can load all required css in .info file of module.

stylesheets[all][] = my_module.css
stylesheets[all][] = override.css

After that you can use hook_css_alter() function to unset your css conditionally.

Pushpinder Rana #pushpinderdrupal
Acquia Certified Drupal Expert

jaypan’s picture

If the CSS is site-specific, it shouldn't be added in the module, it should be added in the theme. It can be a good idea to add default styles in your module, so that the output doesn't look like a dog's mess before it's themed in the theme, but site specific theming should always be done in the theme. This allows you to change the theme on the site later on in the future as well.

Contact me to contract me for D7 -> D10/11 migrations.

orkideh’s picture

try to add your css and js in hook_init after checking domain,
or
build admin panel and let admin choose any style it make you module more custom and lovely

nevets’s picture

Note using hook_init() does not work well with page caching.

orkideh’s picture

yeh its maybe,

what about admin panel to theme?! and clear cache after admin selection