How can I produce results similar to this: http://www.activefarming.com/hay-directory ?

I have looked in:

* The source code of that page --> no use!
* Sample code from the net such as:

      $rowcolor1 = '#0000FF';
      $rowcolor2 = '#FF0000';
       echo '  
   <table style="caption-side:top; border-collapse:collapse">';  
       for ($n = 0; $n < count(DISTINCT($nid)); $n++)  
       {  
           if($n % 2 == 1)  
           {  
                 $style = $rowcolor1;  
           }else{  
                $style = $rowcolor2;   
           }  
           echo '  
       <tr style="background:'.$style.';">........ etc.
    

and:

      $color1 = '#FF0000';
      $color1 = '#0000FF';
      <? $row_count=0; ?>
      <table>
      <? $row_color = ($row_count % 2) ? 'color1' : 'color2'; ?>
      <tr class="<?=$row_color; ?>"><td>sample</td></tr>
      <? $row_count++; ?>
      </table>
    

* The source code of other modules (e.g. watchdog module) such as:

      $n = count($header);
      for ($i = 0; $i < $n; $i++) {
      $output .= '<tr class="' . ($i % 2 == 0 ? 'even' : 'odd') . '"><th>' . $header[$i] . '</th><td>' . $data[$i] . '</td></tr>';
      }
    

The code works, but the problem is that the node-flexinode-n.tpl.php file is run each every time a new record is brought from the database, which means that each time the variable will take the value of the first color.

Any help is most appreciated.

Mi

Comments

Tiburón’s picture

Hi xDreamer

Have a look at this page:

Making additional variables available to your templates | drupal.org
http://drupal.org/node/16383

There is an example of how to pass a $zebra to a template for in this case comments. The $zebra having the value of either 'odd' or 'even'.

Just modify the code to address node-flexinode-n.tpl.php instead of comments.tpl.php.

Regards,

Christian Larsen

xDreamer’s picture

Thank you Tiburón.. I'll give it a try..

I guess those function codes go into the template.php.. if I'm wrong please correct me.

Mi

Tiburón’s picture

Hi xDreamer

Just to remove any doubt you or other readers may have.

Yes the customized functions live in your template.php file in your theme template folder.

A quote from the beginnig of the page I referred you to:

[...] This function needs to be defined in a template.php file, which is placed inside the template directory [...]

The template.php file is called/included before your *.tpl.php so basically anything you define there will be available to your *.tpl.php files.

This means you can do a lot to customize your theme beyond what Drupal delivers out of the box. For inspiration:

PHPTemplate Theme Snippets | drupal.org
http://drupal.org/node/45471

Have fun :-)

Regards,

Christian Larsen

xDreamer’s picture

I've tried and it worked. Thank you. :)

Mi

drupalfantwo’s picture

Thank you for posting this, the information in the links are too much for me to handle is there an actual example you can link me to see.

Thank you