我正在努力想出一种在Drupal视图中建立颜色编码的方法。我有几个需要,但无法弄清楚如何做到这一点。以下是一些例子......
任何人都有这方面的想法?我怀疑我们可能在正常的网页中抓取条件值,但这在Drupal中很棘手并且我的javascript知识有限。我知道使用好的SQL我们可以在值上运行一些PHP并关联一个css选择器来执行此操作,但我正在尝试在视图中完成它(提供的modlue)。 提前致谢
答案 0 :(得分: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>