用户登录

Drupal资源链接

http://zhupou.cn
drupal布道者,改成了"老葛的Drupal培训班",专心于培训事业
http://drupal.org
官方网站
http://drupalchina.org
中文的官方网站
http://acquia.com/
本站就是用这个版本构建的

对切换样式的再思考

今天重新对切换样式列表功能进行重写.按照NewsFlash模板的方式进行.是用了JS写cookie,然后用php读取cookie中的样式名称,进行样式表的加载.

js代码如下(newsflashstyle是cookie的变量名:

function pickstyle(whichstyle) {
  var expireDate = new Date()
  var expstring=expireDate.setDate(expireDate.getDate()+3000000)
  document.cookie = "newsflashstyle=" + whichstyle + "; expires="+expireDate.toGMTString()
}

在模板中使用get_newsflash_style进行样式加载.

function get_newsflash_style() {
  $style = theme_get_setting('newsflash_style');
  if (!$style)
  {
    $style = 'blue';
  }
  if (isset($_COOKIE["newsflashstyle"])) {
    $style = $_COOKIE["newsflashstyle"];
  }
  return $style;
}
$style = get_newsflash_style();
drupal_add_css(drupal_get_path('theme', 'newsflash') . '/css/' . $style . '.css', 'theme');

这样做的问题就是不能使用缓存,对于游客来讲,如果开启了缓存系统.那么这样切换样式的功能是没有办法使用的.对于登录用户来说倒是好用,因为drupal中登录用户是不启用缓存的.

思考

这样做的问题就是不能使用缓存,对于游客来讲,如果开启了缓存系统.那么这样切换样式的功能是没有办法使用的.对于登录用户来说倒是好用,因为drupal中登录用户是不启用缓存的.