2

Drupalビューでカラーコーディングを開始する方法を考えています。これにはいくつかのニーズがありますが、その方法がわかりません。下記は用例です...

  1. コンテンツタイプのテーブルビューで、投稿の年齢に基づいて各行を色分けしたいと思います。つまり、投稿の「年齢」はテーブルの列の1つであり、投稿が1日未満の各行を黄色の背景で強調表示する必要があります。1週間以上の場合は、赤でハイライトします。

誰かがこれについてのアイデアを持っていますか?通常のWebページで条件値を取得できる可能性があると思いますが、これはDrupalでは注意が必要であり、JavaScriptの知識は限られています。私は良いoleSQLで、値に対してPHPを実行し、これを行うためにcssセレクターを関連付けることができることを知っていますが、ビュー(提供されたモジュール)でそれを達成しようとしています。前もって感謝します

4

1 に答える 1

1

日付に応じてクラスに挿入するviews-view-table--Temp.tpl.php(Tempはビュー名)を作成します。これは、作成日をTime Agoを表示するように変更し、週または日にストライプで検索した例です。phpdatemathまたは他のメソッドを使用してクラスを挿入できます。これは非常に基本的なことであり、微調整が必​​要になります。

<?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>
于 2010-01-12T19:18:28.103 に答える