Hi I have created a tracker: www.allbuyart.com/tracker I want to edit the theme so i've added a file called views-view-table--tracker.tpl.php

I want to edit the view theme so that the picture is on the left the title is on top right and the teaser is on the bottom right. I know how to build a table to do this but the problem i'm having is that I can't figure out which bit of PHP is unique to the picture, title, teaser

the theme is as follows:

<?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 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>

I need to change the following part of the code but like I say, there's no unique identifier for picture, title, teaser:

  <tbody>
    <?php foreach ($rows as $count => $row): ?>
      <tr class="<?php print implode(' ', $row_classes[$count]); ?>">
        <?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>

Help would be much appreciated.

Cheers

Mike

Comments

jerseycheese’s picture

If you take a peek into the $row array with print_r(), you should be able to find the specific bits you want to print, and print them directly, rather than use the $content variable inside that table cell.

<?php foreach ($row as $field => $content): ?>
          <td class="views-field views-field-<?php print $fields[$field]; ?>">
            <?php print print_r($row, TRUE); ?>
            <?php print $content; ?>
          </td>
<?php endforeach; ?>

Better yet, install the Devel module and you can use dpm() instead:

<?php foreach ($row as $field => $content): ?>
          <td class="views-field views-field-<?php print $fields[$field]; ?>">
          <?php dpm($row); ?>
          <?php print $content; ?>
          </td>
<?php endforeach; ?>

It'll print the entire contents of that $row array in a cleaner and more understandable way. Once you find what you need, you can get rid of $content and print exactly what you want from $row.

nevets’s picture

An alternate approach is to use the Display Suite, make a new build mode, create the layout with Display Suite and use that in views as your row style.

phatmike10’s picture

Thank you for this, I change the code to:

<tbody>
    <?php foreach ($rows as $count => $row): ?>
      <tr class="<?php print implode(' ', $row_classes[$count]); ?>">
<?php foreach ($row as $field => $content): ?>
          <td class="views-field views-field-<?php print $fields[$field]; ?>">
            <?php print print_r($row, TRUE); ?>
            <?php print $content; ?>
          </td>
<?php endforeach; ?>
      </tr>
    <?php endforeach; ?>
  </tbody>

as you can see at www.allbuyart.com/tracker the array names have appeared, so I altered the code to:

<tbody>
    <?php foreach ($rows as $count => $row): ?>
      <tr class="<?php print implode(' ', $row_classes[$count]); ?>">
<?php foreach ($row as $field => $content): ?>
          <td class="views-field views-field-<?php print $fields[$field]; ?>">
            <?php print print_r($row, TRUE); ?>
            <?php print $field_image_fid; ?>
          </td>
<?php endforeach; ?>
      </tr>
    <?php endforeach; ?>
  </tbody>

however it doesn't seem to work, I wanted it to just display the image.

ultimately I want something like this:

<tbody>
    <?php foreach ($rows as $count => $row): ?>
      <tr class="<?php print implode(' ', $row_classes[$count]); ?>">
<?php foreach ($row as $field => $content): ?>
          <td class="views-field views-field-<?php print $fields[$field]; ?>">
            <?php print print_r($row, TRUE); ?>
            <?php print $field_image_fid; ?>
          </td>
          <td>
                   <tr>
                   <td><?php print $title; ?></td>
                   </tr>
                   <tr>
                   <td><?php print $teaser; ?></td>
                   </tr>              
          </td>
<?php endforeach; ?>
      </tr>
    <?php endforeach; ?>
  </tbody>

ideally i'd like to know how do the above by just altering the php/html for this file without download more modules.

thanks

phatmike10’s picture

Any help would be much appreciated.

cheers

Mike