2011-12-21 59 views
2

我想加載一個CSS文件到主頁只有在Drupal 7,並得到了幫助,在做到這一點。現在我只需要在主頁上省略另一個css文件。我想我可以添加和其他語句,但是這產生了一個錯誤。這裏是template.php文件的代碼。CSS文件加載首頁只省略其他drupal 7

function fource_preprocess_html(&$vars) { 
    if($vars['is_front']) { 
    drupal_add_js(drupal_get_path('theme','fource').'/js/image_scale.js'); 
    drupal_add_css(drupal_get_path('theme','fource').'/css/index_style.css'); 
    } 
} 

這是我的嘗試:

function fource_preprocess_html(&$vars) { 
    if($vars['is_front']) { 
    drupal_add_js(drupal_get_path('theme','fource').'/js/image_scale.js'); 
    drupal_add_css(drupal_get_path('theme','fource').'/css/index_style.css'); 
    }else{ 
    drupal_add_css(drupal_get_path('theme','fource').'/css/main.css'); 
} 

誰能告訴我,爲什麼這不起作用?

+0

它通常有助於說明你得到什麼錯誤; – 2011-12-22 12:46:54

回答

3

您剛剛錯過了else語句的閉包(缺少一個大括號)。將您的代碼更改爲以下內容:

function fource_preprocess_html(&$vars) { 
    if ($vars['is_front']) { 
    drupal_add_js(drupal_get_path('theme','fource').'/js/image_scale.js'); 
    drupal_add_css(drupal_get_path('theme','fource').'/css/index_style.css'); 
    } 
    else { 
    drupal_add_css(drupal_get_path('theme','fource').'/css/main.css'); 
    } // <-- this is the bit you're missing 
} 
0

我這樣做了insidfe html.tpl.php。任何人都有理由認爲這是一個不好的解決方案?

<?php print $styles; ?> 
<style type="text/css" media="screen"> 
    @import url(/sites/all/themes/PATH-TO-CSS); 
    <?php if ($is_front):?> 
     @import url(/sites/all/themes/PATH-TO-HOME-ONLY.css); 
    <?php endif; ?> 
</style> 
+1

問題被標記爲'drupal',而不是'php'。 – 2012-10-10 03:18:28