I set at the .info module file the parameter to add a css file,

stylesheets[all][] = css/style.css

but it is not attached even if I clear the cache.

I have look for the web to get the reason but apparently is all I might have to do.

Anybody could tell me what am I missing please? Here the code: https://github.com/jmvelasco/drupal

The js files are attached.

Thanks in advance.

3 Answers 3


I loaded your module into my dev, there were some install errors but I got through that part to the actual problem you are having. You need to rename your CSS file. The common convention is to name it 'slider.css', since that is the name of your module. It never gets loaded with the 'style.css' though due to your theme probably having the same named stylesheet. Once I changed the name it loaded after clearing the cache. Hope that helps, will post a more detailed explanation when I have a little more time.

Also: See comment about using '#attached' method for this. It would be cleaner. Original Comment: 'If you are trying to attach CSS that is supposed to show up on a page hen that block is present you should be using 'attached' to load the CSS. Ref: drupal.org/node/2278795'

In your current module code you can use #attach method like below:

   // Line 134 of slider.module, make content array and use #markup for content
   // Then use #attach method to finish out render array.
   $block = array(
        'subject' => t('Show Nodes Block'),
        'content' => array(
            '#markup' => $output,
    // Add CSS File with changed name as well.
    $block['content']['#attached']['css'] = array(
        drupal_get_path('module', 'slider') . '/css/slider.css',

    return $block;

  • #attached method is not working for me
    – manou
    Jan 19, 2015 at 11:16
  • I know that not using #attach and using .info is probably working for you but I added the way to use #attach in your current module implementation so you could see both ways. The block would have to be on the page for this to actually work, but I tested it and it worked. Jan 19, 2015 at 18:20
  • The error might be a dependency with Link module, I added this dependency to the info file, thanks. Your code gives me a PHP error: "Cannot use string offset as an array", but I tried again following your reference at the other comment and it is working now. I was probably missing the module path before the css file. Thank you for following!
    – manou
    Jan 19, 2015 at 20:15

It could be as simple as just clearing cache or just visiting the 'modules' page in your admin. The content of .info files is cached and isn't reloaded with every page visit.

  • Missing cleaning the cache is one of the first mistakes a new drupalist use to comes into, but this is not the case. Indeed if it would be, the js files were not attached neither until cleaning, but they are. In fact I clean caches. The css is still missing. Other idea_
    – manou
    Jan 18, 2015 at 22:16
  • Looking at the css file, it's very big. Could you, as a test, replace the entire content by 'body{background:black}' and clear cache? See if it's included now. Jan 18, 2015 at 22:33

You should clear the caches.

Another alternative would be to use a module for CSS. This is a great article about modules for css. CSS for Drupal 7 Site Builders

  • I have a custom css file I would like to attach to the page when the block defined in the module is being rendered. I use to clear caches after every module change. This doesn-t solve the problem. Thanks but the way.
    – manou
    Jan 18, 2015 at 22:19
  • If you are trying to attach CSS that is supposed to show up on a page hen that block is present you should be using 'attached' to load the CSS. Ref: drupal.org/node/2278795 Jan 19, 2015 at 0:36
  • The attach approach has not worked for CSS, I achieve it with js files only from hook_form_alter adding to #attached array-key a list of js files inside [js]. any idea why could not work always?
    – manou
    Jan 19, 2015 at 11:15

Your Answer

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

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