Reply to comment

Views2: In Raster-Ausgaben even und odd / gerade und ungerade zeilen per CSS-Klasse ansprechen

Leider ist es in den Views nicht "von Werk aus" vorgesehen, dass die Zeilen einer Raster-(HTML-)Tabellenausgabe per CSS-Klasse für gerade und ungerade zeilen gekennzeichnet werden.

Da es allerdings häufiger der Fall ist, dass man die Zeilen oder Werte entsprechend greifen möchte, hier ein kurzer Tipp:

Um alle Views mit dem Rastertyp anzusprechen:

  1. Datei "views-view-grid.tpl.php im Theme-Ordner erstellen
  2. Folgenden Code in die Datei einfügen und schon läufts:

    1. // $Id: views-view-grid.tpl.php,v 1.3 2008/06/14 17:42:43 merlinofchaos Exp $
    2. /**
    3.  * @file views-view-grid.tpl.php
    4.  * Default simple view template to display a rows in a grid.
    5.  *
    6.  * - $rows contains a nested array of rows. Each row contains an array of
    7.  *   columns.
    8.  *
    9.  * @ingroup views_templates
    10.  */

     if (!empty($title)) :
     print $title;
     endif;

     foreach ($rows as $row_number => $columns):

    1.         $row_class = 'row-' . ($row_number + 1);
    2.         if ($row_number == 0) {
    3.           $row_class .= ' row-first';
    4.         }
    5.         elseif (count($rows) == ($row_number + 1)) {
    6.           $row_class .= ' row-last';
    7.         }
    8.        
    9.         //#JP060409:
    10.         //Even/Odd hinzufügen
    11.         if($row_number % 2){
    12.                 //Odd
    13.                 $row_class .= ' row-even';
    14.         } else {
    15.                 //Even
    16.                 $row_class .= ' row-odd';
    17.         }
    18.      

    1.  foreach ($columns as $column_number => $item):
    2.         $col_class = '';
    3.         //#JP060409:
    4.         //Even/Odd hinzufügen
    5.         if($column_number % 2){
    6.                 //Odd
    7.                 $col_class .= ' col-even';
    8.         } else {
    9.                 //Even
    10.                 $col_class .= ' col-odd';
    11.         }
    12.        

     print $item;

     endforeach;

     endforeach;

  3. Cache leeren nach Fertigstellung nicht vergessen!!!
Einordnung:

Reply

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Internal paths in single or double quotes, written as "internal:node/99", for example, are replaced with the appropriate absolute URL or path. Paths to files in single or double quotes, written as "files:somefile.ext", for example, are replaced with the appropriate URL that can be used to download the file.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><blockquote>
  • Lines and paragraphs break automatically.
  • Pairs of<blockquote> tags will be styled as a block that indicates a quotation.
  • You can enable syntax highlighting of source code with the following tags: <c>, <cpp>, <css>, <drupal5>, <drupal6>, <java>, <javascript>, <mysql>, <php>, <python>, <ruby>, <smarty>, <xml>. The supported tag styles are: <foo>, [foo]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.
  • Textual smileys will be replaced with graphical ones.
  • Each email address will be obfuscated in a human readable fashion or (if JavaScript is enabled) replaced with a spamproof clickable link.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.