2011-03-29 22 views
0

我期待實施基於CSS樣式的分類術語;特別是對於我想添加當前術語的身體標記。如何使用drupal template.php做基於分類的css樣式?

現在,這裏是我到目前爲止有:

function _phptemplate_variables($hook, $vars = array()) { 
    global $node; 
    switch ($hook) { 
     case 'page':   die ('test'); 
      $vars['body_class'] = ''; 
      if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) { 
       $vars['body_class'] = 'theme'.arg(2); 
      } 
      if (arg(0) == 'node' && is_numeric(arg(1))) { 
       $node = node_load(arg(1)); 
       if (is_array($node->taxonomy)) { 
        foreach ($node->taxonomy as $term) { 
         $vars['body_class'] .= 'theme'.$term->tid; 
        } 
       } 
      } 

      if (drupal_is_front_page()) { 
       $vars['body_class'] .= ' front'; 
      } 
      break; 
    } 
    return $vars; 
} 

我覺得代碼是好,但它永遠不會被調用(見我「死」功能);使用簡單的phptemplate引擎和最小的drupal6安裝。

我在這裏錯過了什麼特別的東西?

+0

您是否刷新了緩存? – acm 2011-03-29 13:56:31

+0

yes,thousand times :) – Disco 2011-03-29 14:03:23

+0

function _phptemplate_variables($ hook,$ vars){die('here'); }也永遠不會被執行。 – Disco 2011-03-29 14:03:57

回答

1
/** 
* Override or insert PHPTemplate variables into the templates. 
*/ 
function phptemplate_preprocess_page(&$vars) { 
    // 
} 

/** 
* Override or insert PHPTemplate variables into the templates. 
*/ 
function phptemplate_preprocess_node(&$vars) { 
    // 
} 
0

對於Drupal 7,更優雅的解決方案可能是使用Context module。有關詳細信息和說明,請參閱以下文章。

語境模塊允許用於創建特定的Drupal頁,例如任意的上下文根據分類術語。這些上下文可以觸發某些反應,例如添加一個具有所選分類術語的CSS類。

+0

單鏈接的答案不是最好的。請簡單地描述一下URL末尾的內容 – Marius 2013-12-05 12:58:34