Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
1  
Have you cleared the cache? – hpn Jan 26 '12 at 10:04
That cache located at admin/config/development/performance? Multible times. – rekire Jan 26 '12 at 10:35
Can you put your function here? – hpn Jan 26 '12 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 '12 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 '12 at 10:36

1 Answer

up vote 2 down vote accepted

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');
share|improve this answer
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 '12 at 11:19
In hook_init write an exit command to see whether the hook is called or not. – hpn Jan 26 '12 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 '12 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 '12 at 19:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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