0

Well I know that I have to use drupal_add_css like described here.

But that doesn't work and I don't understand why.

I tried to use this hooks: function hook_init, hook_views_pre_render, hook_preprocess_html and hook_preprocess_page.

I tried in that hooks this code:

$css=drupal_add_css(drupal_get_path('module', 'mymodule') . '/style.css');
$variables['styles'] = drupal_get_css($css);

or:

drupal_add_css(drupal_get_path('module', 'mymodule') . '/style.css');
$variables['styles'] = drupal_get_css();

or also just the first line.

also:

drupal_add_css("/".drupal_get_path('module', 'mymodule') . '/style.css');

or that:

drupal_add_css(drupal_get_path('module', 'mymodule') . '/style.css',
               array('group' => CSS_DEFAULT, 'every_page' => TRUE));

Here is my style.css:

#logo {
    display:none;
}

That should hide the logo on success. What is wrong with my tries?

5
  • 1
    Have you cleared the cache?
    – hpn
    Jan 26, 2012 at 10:04
  • That cache located at admin/config/development/performance? Multible times.
    – rekire
    Jan 26, 2012 at 10:35
  • Can you put your function here?
    – hpn
    Jan 26, 2012 at 10:43
  • could use a little more information on what isn't working -- have you used firebug / developer tools before? I've found this to be helpful in the past for debugging drupal_add_ issues. Check the 'resources' / 'elements' tab in these tools and look for where this file is 404'ing to see where its failing. If its not there, the problem is probably in your surrounding hook.
    – schnippy
    Jan 26, 2012 at 21:07
  • @schnippy I don't know why but the reason was the name of the file. After I changed the filename the file was included to the sourcecode. Btw. I use firebug.
    – rekire
    Jan 27, 2012 at 10:36

1 Answer 1

2

in hook_init, removing the first slash should solve the problem. If not, check for permissions.

drupal_add_css("/".drupal_get_path('module', 'mymodule') . '/style.css');

Should be

drupal_add_css(drupal_get_path('module', 'mymodule') . '/style.css');
4
  • No sorry that doesn't work. Like I wrote above I tested all variations. That one above is just the currient try.
    – rekire
    Jan 26, 2012 at 11:19
  • In hook_init write an exit command to see whether the hook is called or not.
    – hpn
    Jan 26, 2012 at 11:31
  • If I uncomment the line above (die('<a href="/'.drupal_get_path('module', 'mymodule') . '/style.css">test</a>');) I'll get a link to my css file.
    – rekire
    Jan 26, 2012 at 11:33
  • The problem seems to be the name of the css file. If I change it to blah.css everything works. I'll accept your answer anyway because you pointed to the small error in my example above.
    – rekire
    Jan 26, 2012 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.