0

I am trying to create an image gallery, using Views 3 for Drupal 7. A brief overview of what I did:
- Create custom content type for photo gallery (title and image fields
- Create View for the gallery page
- Set format to "Grid", and show to "Fields" - Added field: "Content: Photo" (preview image style) - Added field: "Content: Photo" (thumbnail image style)

As you can see, I have two fields with the same field so that I can have two differently sizes of each image. What I need to do, is print these images in two different places in my template.

This is my views-view-grid--gallery.tpl.php:

<table>
  <?php foreach ($rows as $row_number => $columns): ?>
    <tr>
      <?php foreach ($columns as $column_number => $item): ?>
        <td>
          <?php print $item; ?>
        </td>
      <?php endforeach; ?>
    </tr>
  <?php endforeach; ?>
</table>

I want to be able to do something like this:

<table>
  <tr>
    <?php // foreach ?>
      <td>          
        <?php // print preview image ?>
      </td>
  </tr>
</table>

<div class="thumbnails">
  <?php // foreach ?>
    <?php // print thumbnail image ?>
</div>

I have tried a multitude of things, but I can only make $item print either one of the images, or both of the images. Since only the final, HTML-formatted image is returned, I can't figure out how it is possible to split it up.

Thanks much in advance!

  • If you want to control the printing of individual fields within a row use views-view-fields.tpl.php – rooby May 2 '13 at 10:57
  • I tried that, but I still can't print $item in different places in grid.tpl.php. I was able to only show one of the fields, but I need to show one field inside a table, and the other field inside a div outside of the table. How can I achieve this? Fields just passes back plaintext, not an array or anything. – scootstah May 2 '13 at 17:15
  • After the second foreach can you do an if to check that the item is not a thumbnail item, so that thumbnails are skipped in the table. - Then after the table you could do the foreach's again and only print the thumbnails. – rooby May 2 '13 at 17:22
  • How? $item contains the HTML content for the whole row, there is no way to separate it unless I manipulate the string... and there has to be a better solution than that. Do you mind showing an example snippet? – scootstah May 2 '13 at 18:14
  • Sorry I got confused for a moment and thought that $item was a field, not a row. In that case I misunderstood - so you want to print indvidual fields, like in views-view-fields.tpl.php, but you want to do it in views-view-grid.tpl.php – rooby May 3 '13 at 0:00
1

Anyone still looking for this, that's how I did it:

First I've created a simple view with a block to show just the fields that I needed on top (let's call it view-top), striped all default elements and classes to make it clean and easier to work (not really necessary to clean it). In OP's case would be the miniature for the gallery.

Then I've made my main view with the fields that I wanted on bottom (let's call it view-bottom). In OP's case would be the full sized images. In the header of this view I've added a "Global: Visualization area" and called my view-top.

This way I had two views, one embedded in the other, and with a bit of Drupal's behaviors I've made the click logic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.