2009-12-30 100 views
2

我試圖想出一種在Drupal視圖中構建顏色編碼的方法。我有幾個需要,但不知道如何去做。以下是一些示例...Drupal:顏色編碼視圖

  1. 在內容類型的表格視圖中,我想根據帖子的年齡對每行進行顏色編碼。換句話說,帖子的「年齡」是表中的一列,我希望每一行的帖子少於一天的時候都會以黃色背景突出顯示。如果超過一週,用紅色突出顯示,等等......

任何人對此有何想法?我懷疑我們可能可以在普通網頁中獲取條件值,但這在Drupal中很棘手,而且我的JavaScript知識有限。我知道有良好的SQL SQL,我們可以在值上運行一些PHP,並將一個CSS選擇器關聯到一個CSS中,但我試圖在視圖中完成它(貢獻模型)。 在此先感謝

+0

在這個例子中,你如何生成表?使用模板(tpl.php)文件?或通過使用另一個模塊? – dusan 2010-01-06 17:49:16

+0

Views模塊 - 我不介意編寫SQL - 但我喜歡視圖的靈活性 - 例如參數,塊,簡單的ajax等...... – tpow 2010-01-11 07:06:51

回答

1

我會創建一個views-view-table-Temp.tpl.php(其中Temp是視圖名稱),根據日期插入類中。下面是一個例子,我將創建的日期更改爲顯示Time Ago,並在帶有stripos的Week或Day上搜索。您可以使用php日期數學或其他方法來插入您的課程。這是非常基本的,將需要調整:

<?php 
// $Id: views-view-table.tpl.php,v 1.8 2009/01/28 00:43:43 merlinofchaos Exp $ 
/** 
* @file views-view-table.tpl.php 
* Template to display a view as a table. 
* 
* - $title : The title of this group of rows. May be empty. 
* - $header: An array of header labels keyed by field id. 
* - $fields: An array of CSS IDs to use for each field id. 
* - $class: A class or classes to apply to the table, based on settings. 
* - $row_classes: An array of classes to apply to each row, indexed by row 
* number. This matches the index in $rows. 
* - $rows: An array of row items. Each row is an array of content. 
* $rows are keyed by row number, fields within rows are keyed by field ID. 
* @ingroup views_templates 
*/ 
?> 
<table class="<?php print $class; ?>"> 
    <?php if (!empty($title)) : ?> 
    <caption><?php print $title; ?></caption> 
    <?php endif; ?> 
    <thead> 
    <tr> 
     <?php foreach ($header as $field => $label): ?> 
     <th class="views-field views-field-<?php print $fields[$field]; ?>"> 
      <?php print $label; ?> 
     </th> 
     <?php endforeach; ?> 
    </tr> 
    </thead> 
    <tbody> 
    <?php foreach ($rows as $count => $row): ?> 
     <tr class="<?php print implode(' ', $row_classes[$count]); ?> <?php 
     if(stripos($row["created"], "Week")) { 
       print "week-class "; 
     } 
     if(stripos($row["created"], "Day")) { 
       print "day-class "; 
     }?> 
     "> 
     <?php foreach ($row as $field => $content): ?> 
      <td class="views-field views-field-<?php print $fields[$field]; ?>"> 
      <?php print $content; ?> 
      </td> 
     <?php endforeach; ?> 
     </tr> 
    <?php endforeach; ?> 
    </tbody> 
</table> 
+0

我還沒有測試過,但你的邏輯是正確的。謝謝 – tpow 2010-01-15 21:07:52