2

I am trying to add a CSS file to a specific internal basic page in Drupal 7 with no success.
After enabling the clean URL paths and add a path for my internal basic page I am able to capture the path using $path=drupal_get_path_alias();.

After that, I am trying to put condition statements so when a specific path is loaded a specific CSS file is loaded. I have this piece of code in ninesixty_preprocess_page(&$vars, $hook) in the template.php file.

if($path == 'about/advantages') {
  drupal_add_css(drupal_get_path('theme', 'ninesixty') . "/page-about.css");
}

I have tested the IF-statement by echoing the $path variable with total success. The page-about.css file does not load at all, though.

Please note that I am using Drupal with WAMP server, and the page-about.css file is located under drupal/sites/all/themes/ninesixty/styles/framework.

2 Answers 2

4

The path is incorrect; it should be as in the following code.

if ($path == 'about/advantages') {
  drupal_add_css(drupal_get_path('theme', 'ninesixty') . "/styles/framework/page-about.css"); 
}
1
  • Reminding of accepting an answer could be fine, but asking also an up-vote is a bit more: Accepting an answer is giving an up-vote.
    – avpaderno
    Commented Jun 12, 2012 at 14:25
0

For adding CSS files to specific pages, you can use the CSS Injector module.

Allows administrators to inject CSS into the page output based on configurable rules. It's useful for adding simple CSS tweaks without modifying a site's official theme—for example, a 'nighttime' color scheme could be added during certain hours. The CSS is added using Drupal's standard drupal_add_css() function and respects page caching, etc.

This module is definitely not a replacement for full-fledged theming, but it provides site administrators with a quick and easy way of tweaking things without diving into full-fledged theme hacking.

1
  • I was hoping to do that myself and not use a module. :) so any other suggestion?
    – paranod
    Commented Jun 6, 2012 at 6:19

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.