drupal_add_css not working drupal_add_css not working php php

drupal_add_css not working


It is not quite clear where you are selecting the template that you have in your example. If you are selecting it from a module then you can just use drupal_add_css in the module rather than the template.

If you have your own theme you can use template_preprocess_page and put logic in there to add the relevant CSS (you can also use it to select the template to use).


I have noticed something weird and it might fix your problem:

drupal_add_css( drupal_get_path('theme','themname') . '/working.css','module' ,'all' , false );drupal_add_css( drupal_get_path('theme','themname') . '/path/to/folder/notworking.css','module' ,'all' , false );

The first one will work ebcause the style it in the main them folderThe second line will not work because the style is in a sub folder !

Edit:

i think it did not work because i did not write the path the the style file properly :S so please disregard my answer

drupal_add_css( drupal_get_path('theme','test') . '/pages/subpage/style.css','theme');

is working


This function wont work in templates. The reason is that the variable $styles which will hold all the stylesheet html will already have been generated at this point, so drupal_add_css wont work as it adds to that. if you want to do this in your theme, you would probably have to add the css file manually

<link rel="stylesheet" ... />

The other way would be to use drupal_add_css in a module, but you might have a hard time adding the correct css files on the pages you want.