2009-12-30 104 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