I'm not getting something here when it comes to this variable. What I want to do is bring a global.css file that is based of Yahoo/Meyer's global css file for all pages. So I assume I do this in the .info file:

stylesheets[all][] = global.css

Thats fine and dandy.

But how about when I need to bring in the css file for say the home page only, home.css?
Suppose I want my section pages to have their own css file section.css?
Further, suppose I want to override the default section page and bring in, say a different css file, news.css for my news section?

If I do this:
stylesheets[home][] = home.css
stylesheets[section][] = section.css
stylesheets[news][] = news.css

I don't see how I am going to bring these in on a per page basis.

The $scripts variable follows along the same line. Suppose I only want a certain javascript code to be placed on a certain page? How do avoid it from being a global issue?

Comments

Jeff Burnz’s picture

You have to use the API instead of the .info file method.

Use drupal_add_css and drupal_add_js functions in template.php to conditionally load the files.

Need help with IE?
Learn basic XHTML and CSS first.
Get smart with web specs.

bachbach’s picture

two function in template.php wich automaticly load css and js files following page path alias as : page-front.tpl.php / script-front.js / style-front.css

function _addTemplateFiles($templateFilesSuggestions = false){
	if($templateFilesSuggestions){
		$files_schemes = array();
		if(drupal_is_front_page()){
			$files_schemes[] = "front";
		}else{
			foreach($templateFilesSuggestions as $page){
				$c = count($files);
				if($c > 0){
					$files_schemes[] = $files[$c-1]."-".$page;
				}else{
					$files_schemes[] = $page;
				}
			}
			$files_schemes = array_reverse($files_schemes);
		}
		
		$them_path = path_to_theme();
		
		/* JS */
		$file_path = $them_path."/script.js";
		if(file_exists($file_path)){
			drupal_add_js($file_path, "theme");
		}
		foreach($files_schemes as $file){
			$jsFile_path = $them_path."/script-".$file.".js";
			if(file_exists($jsFile_path)){
				drupal_add_js($jsFile_path, "theme");
				break;
			}
		}
		
		/* CSS screen */
		foreach($files_schemes as $file){
			$cssFile_path = $them_path."/style-".$file.".css";
			if(file_exists($cssFile_path)){
				drupal_add_css($cssFile_path, "theme", "screen", true);
				break;
			}
		}
	}
}
function _phptemplate_variables($hook, $vars = array()) {
if (module_exists('path')) {
    $alias = drupal_get_path_alias($_GET['q']);
    if ($alias != $_GET['q']) {
			$path_parts = array();
			foreach (explode('/', $alias) as $path_part) {
				if($path_part != 'fr' && $path_part != 'en'){
           $path_parts[] = $path_part;
				}
			}
		}
	}
	//
	_addTemplateFiles($path_parts);
 
  return $vars;
}