I am having troubles getting a stylesheet to implement.

I have created a module called mymod. The module is located at sites/all/modules/mymod/

In the mymod.module file, I registered a theme hook using mymod_theme(). I then created the default theme using theme_mymod(). Within the default theme, I added a css sheet using the following code:

 $module_path = drupal_get_path('module', 'mymod');
$full_path = $module_path . "/mymod.css";
drupal_add_css($full_path); 

Everything is fine up to this point. My default theme works, and the CSS inside mymod.css displays properly.

Now I have also created a theme called mytheme. The theme is located at sites/all/themes/mytheme/

In the mytheme.info, I have tried to include mymod.css using:

stylesheets[all][] = mymod.css

I have also tried

stylesheets[screen][] = mymod.css

But neither work. I have cleared my cache to make sure that it wasn't a caching problem, but no matter what I do, the CSS in mymod.css won't appear. Does anybody have any ideas on this one?

Comments

zeta ζ’s picture

To add a css file to your module use something like:

 function mymod_init() {
  drupal_add_css(drupal_get_path('module', 'mymod') . '/mymod.css');
} 

stylesheets[all][] = mymod.css will try to find mymod.css in your theme’s directory and, of course, it isn’t there.
___________________
It’s in the detaιls…

demonstration portfolio

jaypan’s picture

Thank you Zeta, however, I already added the CSS to my module using that same function as I showed in my original post!

The problem is that I want to use the default stylesheet from the module in the theme as well, but I have created a mymod.tpl.php that ends up canceling out the mymod.css. Any ideas how I can do use mymod.css from the module in my theme? The book I have says that I should be able to do it just the way I am in this examaple, by adding it using stylesheets[all][] = mymod.css, but it's not working.

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

jaypan’s picture

It turns out that I had to use drupal_add_css to the mymod.tpl.php file. When I did that, it worked fine. So you had the right idea Zeta, thanks!

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

mcrickman’s picture

You need to flush the cache once you add the css file to the info file.

stylesheets[all][] = mymod.css

Then go to admin area / site settings / performance and click the clear cache button.

Then reload your page.

Charlie

jaypan’s picture

Thanks McRickman, but as I mentioned in the original post, I have tried clearing the cache (I tried after each change), and the stylesheet still isn't implemented.

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

mcrickman’s picture

Oh seemed like you were referring to your browsers cache.

Charlie

jaypan’s picture

My bad, I could have been a little clearer with that.

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

Professional_Developer’s picture

I am just posting this here in case anyone arrives at this node from the search facility.

I had a similar problem, only that my stylesheet appeared in the head of the page, but the style rules were not being implemented. It turned out to be a permissions problem on the server. There were no read permissions set for anyone other than the file owner for 'mymod.css'.

Professional Drupal Development
http://www.protilit.com