Drupal 通过API动态的添加样式文件
生活随笔
收集整理的這篇文章主要介紹了
Drupal 通过API动态的添加样式文件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前面幾篇文章中講到關于樣式的載入方式,已經了解到可以通過 theme.info 加載樣式文件,但都需要更新緩存才可以使用,因些這樣子沒有辦法動態的加載一些樣式文件,在DP中提供了兩個API操作樣式文件?drupal_add_css 、 drupal_get_css
這里,仍然是以 mytheme 為主題,看以下示例:
function template_preprocess_page(&$variables) {$front_style = path_to_theme() .'/front-page.css';$path_style = path_to_theme() .'/path-'. arg(0) .'.css';if (file_exists($front_style) && $variables['is_front']) {$include_style = $front_style;}elseif (file_exists($path_style)) {$include_style = $path_style;}if (isset($include_style)) {drupal_add_css($include_style, 'theme', 'all', FALSE);$variables['styles'] = drupal_get_css();}} 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的Drupal 通过API动态的添加样式文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Drupal 覆写系统样式
- 下一篇: Drupal 引入JS文件的几种方式